doc.odin 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. destroy(&bits)
  17. }
  18. -- A Bit Array can optionally allow for negative indices, if the mininum value was given during creation:
  19. package test
  20. import "core:fmt"
  21. import "core:container/bit_array"
  22. main :: proc() {
  23. Foo :: enum int {
  24. Negative_Test = -42,
  25. Bar = 420,
  26. Leaves = 69105,
  27. }
  28. using bit_array
  29. bits := create(int(max(Foo)), int(min(Foo)))
  30. defer destroy(bits)
  31. fmt.printf("Set(Bar): %v\n", set(bits, Foo.Bar))
  32. fmt.printf("Get(Bar): %v, %v\n", get(bits, Foo.Bar))
  33. fmt.printf("Set(Negative_Test): %v\n", set(bits, Foo.Negative_Test))
  34. fmt.printf("Get(Leaves): %v, %v\n", get(bits, Foo.Leaves))
  35. fmt.printf("Get(Negative_Test): %v, %v\n", get(bits, Foo.Negative_Test))
  36. fmt.printf("Freed.\n")
  37. }
  38. */