core/container/bit_array
container_dynamic_bit_array
Types
2Procedures
16clear
clear :: proc(ba: ^Bit_Array)SourceSets all values in the Bit_Array to zero.
Inputs:
- ba: The target Bit_Array
create
create :: proc(max_index: int, min_index: int, allocator: mem.Allocator = context.allocator) -> (res: ^Bit_Array, ok: bool)SourceA 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)`)
Inputs:
- max_index: maximum starting index
- min_index: minimum starting index (used as a bias)
- allocator: (default is context.allocator)
Returns:
- ba: Allocates a bit_Array, backing data is set to
max-min / 64indices, rounded up (eg 65 - 0 allocates for [2]u64).
destroy
destroy :: proc(ba: ^Bit_Array)SourceDeallocates the Bit_Array and its backing storage
Inputs:
- ba: The target Bit_Array
get
get :: proc(ba: ^Bit_Array, index: uint) -> (res: bool, ok: bool)SourceGets the state of a bit in the bit-array
Inputs:
- ba: Pointer to the Bit_Array
- index: Which bit in the array
Returns:
- res:
trueif the bit atindexis set. - ok: Whether the index was valid. Returns
falseif 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)SourceA 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)`)
Inputs:
- 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)SourceReturns the next bit, including its set-state. ok=false once exhausted
Inputs:
- it: The iterator that holds the state.
Returns:
- set:
trueif the bit atindexis set. - index: The next bit of the Bit_Array referenced by
it. - ok:
trueif the iterator can continue,falseif the iterator is done
iterate_by_set
iterate_by_set :: proc(it: ^Bit_Array_Iterator) -> (index: int, ok: bool)SourceReturns the next Set Bit, for example if 0b1010, then the iterator will return index={1, 3} over two calls.
Inputs:
- it: The iterator that holds the state.
Returns:
- index: The next set bit of the Bit_Array referenced by
it. - ok:
trueif the iterator can continue,falseif the iterator is done
iterate_by_unset
iterate_by_unset :: proc(it: ^Bit_Array_Iterator) -> (index: int, ok: bool)SourceReturns the next Unset Bit, for example if 0b1010, then the iterator will return index={0, 2} over two calls.
Inputs:
- it: The iterator that holds the state.
Returns:
- index: The next unset bit of the Bit_Array referenced by
it. - ok:
trueif the iterator can continue,falseif the iterator is done
len
len :: proc(ba: ^Bit_Array) -> (length: int)SourceGets the length of set and unset valid bits in the Bit_Array.
Inputs:
- ba: The target Bit_Array
Returns:
- length: The length of valid bits.
make_iterator
make_iterator :: proc(ba: ^Bit_Array) -> (it: Bit_Array_Iterator)SourceWraps a Bit_Array into an Iterator
Inputs:
- ba: Pointer to the Bit_Array
Returns:
- it: Iterator struct
set
set :: proc(ba: ^Bit_Array, index: uint, set_to: bool, allocator: mem.Allocator = context.allocator) -> (ok: bool)SourceSets the state of a bit in the bit-array
Conditionally Allocates (Resizes backing data when `index > len(ba.bits)`)
Inputs:
- ba: Pointer to the Bit_Array
- index: Which bit in the array
- set_to:
truesets the bit on,falseto turn it off - allocator: (default is context.allocator)
Returns:
- ok: Whether the set was successful,
falseon allocation failure or bad index
shrink
shrink :: proc(ba: ^Bit_Array)SourceShrinks the Bit_Array's backing storage to the smallest possible size.
Inputs:
- ba: The target Bit_Array
unsafe_get
unsafe_get :: proc(ba: ^Bit_Array, index: uint) -> (bool)SourceGets the state of a bit in the bit-array
Bypasses all Checks
Inputs:
- ba: Pointer to the Bit_Array
- index: Which bit in the array
Returns:
trueif bit is set
unsafe_set
unsafe_set :: proc(ba: ^Bit_Array, bit: int)SourceSets the state of a bit in the bit-array
Bypasses all checks
Inputs:
- ba: Pointer to the Bit_Array
- index: Which bit in the array
unsafe_unset
unsafe_unset :: proc(b: ^Bit_Array, bit: int)SourceUnsets the state of a bit in the bit-array
Bypasses all Checks
Inputs:
- ba: Pointer to the Bit_Array
- index: Which bit in the array
unset
unset :: proc(ba: ^Bit_Array, index: uint, allocator: mem.Allocator = context.allocator) -> (ok: bool)SourceUnsets the state of a bit in the bit-array. (Convienence wrapper for set)
Conditionally Allocates (Resizes backing data when `index > len(ba.bits)`)
Inputs:
- ba: Pointer to the Bit_Array
- index: Which bit in the array
- allocator: (default is context.allocator)
Returns:
- ok: Whether the unset was successful,
falseon allocation failure or bad index