doc.odin 1.2 KB

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