doc.odin 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. A dynamically-sized array of bits.
  3. The Bit Array can be used in several ways:
  4. By default you don't need to instantiate a `Bit_Array`.
  5. Example:
  6. package test
  7. import "core:fmt"
  8. import "core:container/bit_array"
  9. main :: proc() {
  10. using bit_array
  11. bits: Bit_Array
  12. // returns `true`
  13. fmt.println(set(&bits, 42))
  14. // returns `false`, `false`, because this Bit Array wasn't created to allow negative indices.
  15. was_set, was_retrieved := get(&bits, -1)
  16. fmt.println(was_set, was_retrieved)
  17. destroy(&bits)
  18. }
  19. A `Bit_Array` can optionally allow for negative indices, if the minimum value was given during creation.
  20. Example:
  21. package test
  22. import "core:fmt"
  23. import "core:container/bit_array"
  24. main :: proc() {
  25. Foo :: enum int {
  26. Negative_Test = -42,
  27. Bar = 420,
  28. Leaves = 69105,
  29. }
  30. using bit_array
  31. bits := create(int(max(Foo)), int(min(Foo)))
  32. defer destroy(bits)
  33. fmt.printf("Set(Bar): %v\n", set(bits, Foo.Bar))
  34. fmt.printf("Get(Bar): %v, %v\n", get(bits, Foo.Bar))
  35. fmt.printf("Set(Negative_Test): %v\n", set(bits, Foo.Negative_Test))
  36. fmt.printf("Get(Leaves): %v, %v\n", get(bits, Foo.Leaves))
  37. fmt.printf("Get(Negative_Test): %v, %v\n", get(bits, Foo.Negative_Test))
  38. fmt.printf("Freed.\n")
  39. }
  40. */
  41. package container_dynamic_bit_array