doc.odin 1.3 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. Example:
  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 minimum value was given during creation.
  19. Example:
  20. package test
  21. import "core:fmt"
  22. import "core:container/bit_array"
  23. main :: proc() {
  24. Foo :: enum int {
  25. Negative_Test = -42,
  26. Bar = 420,
  27. Leaves = 69105,
  28. }
  29. using bit_array
  30. bits := create(int(max(Foo)), int(min(Foo)))
  31. defer destroy(bits)
  32. fmt.printf("Set(Bar): %v\n", set(bits, Foo.Bar))
  33. fmt.printf("Get(Bar): %v, %v\n", get(bits, Foo.Bar))
  34. fmt.printf("Set(Negative_Test): %v\n", set(bits, Foo.Negative_Test))
  35. fmt.printf("Get(Leaves): %v, %v\n", get(bits, Foo.Leaves))
  36. fmt.printf("Get(Negative_Test): %v, %v\n", get(bits, Foo.Negative_Test))
  37. fmt.printf("Freed.\n")
  38. }
  39. */
  40. package container_dynamic_bit_array