core/container/bit_array

container_dynamic_bit_array

Types

2

Procedures

16

create

create :: proc(max_index: int, min_index: int, allocator: mem.Allocator = context.allocator) -> (res: ^Bit_Array, ok: bool)Source

A helper function to create a Bit Array with optional bias, in case your smallest index is non-zero (including negative).

The range of bits created by this procedure is min_index..<max_index, and the array will be able to expand beyond max_index if needed.

Allocates (`new(Bit_Array) & make(ba.bits)`)

  • max_index: maximum starting index
  • min_index: minimum starting index (used as a bias)
  • allocator: (default is context.allocator)
  • ba: Allocates a bit_Array, backing data is set to max-min / 64 indices, rounded up (eg 65 - 0 allocates for [2]u64).

get

get :: proc(ba: ^Bit_Array, index: uint) -> (res: bool, ok: bool)Source

Gets the state of a bit in the bit-array

  • ba: Pointer to the Bit_Array
  • index: Which bit in the array
  • res: true if the bit at index is set.
  • ok: Whether the index was valid. Returns false if the index is smaller than the bias.

init

init :: proc(res: ^Bit_Array, max_index: int, min_index: int, allocator: mem.Allocator = context.allocator) -> (ok: bool)Source

A helper function to initialize a Bit Array with optional bias, in case your smallest index is non-zero (including negative).

The range of bits created by this procedure is min_index..<max_index, and the array will be able to expand beyond max_index if needed.

Allocates (`make(ba.bits)`)

  • max_index: maximum starting index
  • min_index: minimum starting index (used as a bias)
  • allocator: (default is context.allocator)

iterate_by_all

iterate_by_all :: proc(it: ^Bit_Array_Iterator) -> (set: bool, index: int, ok: bool)Source

Returns the next bit, including its set-state. ok=false once exhausted

  • it: The iterator that holds the state.
  • set: true if the bit at index is set.
  • index: The next bit of the Bit_Array referenced by it.
  • ok: true if the iterator can continue, false if the iterator is done

iterate_by_set

iterate_by_set :: proc(it: ^Bit_Array_Iterator) -> (index: int, ok: bool)Source

Returns the next Set Bit, for example if 0b1010, then the iterator will return index={1, 3} over two calls.

  • it: The iterator that holds the state.
  • index: The next set bit of the Bit_Array referenced by it.
  • ok: true if the iterator can continue, false if the iterator is done

iterate_by_unset

iterate_by_unset :: proc(it: ^Bit_Array_Iterator) -> (index: int, ok: bool)Source

Returns the next Unset Bit, for example if 0b1010, then the iterator will return index={0, 2} over two calls.

  • it: The iterator that holds the state.
  • index: The next unset bit of the Bit_Array referenced by it.
  • ok: true if the iterator can continue, false if the iterator is done

len

len :: proc(ba: ^Bit_Array) -> (length: int)Source

Gets the length of set and unset valid bits in the Bit_Array.

  • ba: The target Bit_Array
  • length: The length of valid bits.

set

set :: proc(ba: ^Bit_Array, index: uint, set_to: bool, allocator: mem.Allocator = context.allocator) -> (ok: bool)Source

Sets the state of a bit in the bit-array

Conditionally Allocates (Resizes backing data when `index > len(ba.bits)`)

  • ba: Pointer to the Bit_Array
  • index: Which bit in the array
  • set_to: true sets the bit on, false to turn it off
  • allocator: (default is context.allocator)
  • ok: Whether the set was successful, false on allocation failure or bad index

shrink

shrink :: proc(ba: ^Bit_Array)Source

Shrinks the Bit_Array's backing storage to the smallest possible size.

  • ba: The target Bit_Array

unsafe_get

unsafe_get :: proc(ba: ^Bit_Array, index: uint) -> (bool)Source

Gets the state of a bit in the bit-array

Bypasses all Checks

  • ba: Pointer to the Bit_Array
  • index: Which bit in the array
  • true if bit is set

unset

unset :: proc(ba: ^Bit_Array, index: uint, allocator: mem.Allocator = context.allocator) -> (ok: bool)Source

Unsets the state of a bit in the bit-array. (Convienence wrapper for set)

Conditionally Allocates (Resizes backing data when `index > len(ba.bits)`)

  • ba: Pointer to the Bit_Array
  • index: Which bit in the array
  • allocator: (default is context.allocator)
  • ok: Whether the unset was successful, false on allocation failure or bad index

Reference search

Find anything

Documentation preferences

Settings

System theme variants

Used only while Theme is set to System.