doc.odin 1.3 KB

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