doc.odin 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dynamic_bit_array
  2. /*
  3. The Bit Array can be used in several ways:
  4. -- By default you don't need to instantiate a Bit Array:
  5. package test
  6. import "core:fmt"
  7. import "core:container/bit_array"
  8. main :: proc() {
  9. using bit_array
  10. bits: Bit_Array
  11. // returns `true`
  12. fmt.println(set(&bits, 42))
  13. // returns `false`, `false`, because this Bit Array wasn't created to allow negative indices.
  14. was_set, was_retrieved := get(&bits, -1)
  15. fmt.println(was_set, was_retrieved)
  16. }
  17. -- A Bit Array can optionally allow for negative indices, if the mininum 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. */