package core:container/bit_array

⌘K
Ctrl+K
or
/

    Overview

    The Bit Array can be used in several ways:

    By default you don't need to instantiate a Bit Array.

    Example:
    package test
    
    import "core:fmt"
    import "core:container/bit_array"
    
    main :: proc() {
    	using bit_array
    
    	bits: Bit_Array
    
    	// returns `true`
    	fmt.println(set(&bits, 42))
    
    	// returns `false`, `false`, because this Bit Array wasn't created to allow negative indices.
    	was_set, was_retrieved := get(&bits, -1)
    	fmt.println(was_set, was_retrieved) 
    	destroy(&bits)
    }
    

    A Bit Array can optionally allow for negative indices, if the minimum value was given during creation.

    Example:
    package test
    
    import "core:fmt"
    import "core:container/bit_array"
    
    main :: proc() {
    	Foo :: enum int {
    		Negative_Test = -42,
    		Bar           = 420,
    		Leaves        = 69105,
    	}
    
    	using bit_array
    
    	bits := create(int(max(Foo)), int(min(Foo)))
    	defer destroy(bits)
    
    	fmt.printf("Set(Bar):           %v\n",     set(bits, Foo.Bar))
    	fmt.printf("Get(Bar):           %v, %v\n", get(bits, Foo.Bar))
    	fmt.printf("Set(Negative_Test): %v\n",     set(bits, Foo.Negative_Test))
    	fmt.printf("Get(Leaves):        %v, %v\n", get(bits, Foo.Leaves))
    	fmt.printf("Get(Negative_Test): %v, %v\n", get(bits, Foo.Negative_Test))
    	fmt.printf("Freed.\n")
    }
    

    Index

    Constants (0)

    This section is empty.

    Variables (0)

    This section is empty.

    Procedure Groups (0)

    This section is empty.

    Types

    Bit_Array ¶

    Bit_Array :: struct {
    	bits:         [dynamic]u64,
    	bias:         int,
    	length:       int,
    	free_pointer: bool,
    }
    Related Procedures With Parameters
    Related Procedures With Returns

    Bit_Array_Iterator ¶

    Bit_Array_Iterator :: struct {
    	array:    ^Bit_Array,
    	word_idx: int,
    	bit_idx:  uint,
    }
    Related Procedures With Parameters
    Related Procedures With Returns

    Constants

    This section is empty.

    Variables

    This section is empty.

    Procedures

    clear ¶

    clear :: proc(ba: ^Bit_Array) {…}
     

    Sets all values in the Bit_Array to zero.

    Inputs:
    ba: The target Bit_Array

    create ¶

    create :: proc(max_index: int, min_index: int = 0, allocator := context.allocator) -> (res: ^Bit_Array, ok: bool) #optional_ok {…}
     

    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)`)

    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 / 64 indices, rounded up (eg 65 - 0 allocates for [2]u64).

    destroy ¶

    destroy :: proc(ba: ^Bit_Array) {…}
     

    Deallocates the Bit_Array and its backing storage

    Inputs:
    ba: The target Bit_Array

    get ¶

    get :: proc(ba: ^Bit_Array, #any_int index: uint) -> (res: bool, ok: bool) #optional_ok {…}
     

    Gets the state of a bit in the bit-array

    Inputs:
    ba: Pointer to the Bit_Array index: Which bit in the array

    Returns:
    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 = 0, allocator := context.allocator) -> (ok: bool) {…}
     

    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)`)

    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) {…}
     

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

    Inputs:
    it: The iterator that holds the state.

    Returns:
    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) {…}
     

    Returns 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: 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) {…}
     

    Returns 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: true if the iterator can continue, false if the iterator is done

    len ¶

    len :: proc(ba: ^Bit_Array) -> (length: int) {…}
     

    Gets 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) {…}
     

    Wraps a Bit_Array into an Iterator

    Inputs:
    ba: Pointer to the Bit_Array

    Returns:
    it: Iterator struct

    set ¶

    set :: proc(ba: ^Bit_Array, #any_int index: uint, set_to: bool = true, allocator := context.allocator) -> (ok: bool) {…}
     

    Sets 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: true sets the bit on, false to turn it off allocator: (default is context.allocator)

    Returns:
    ok: Whether the set was successful, false on allocation failure or bad index

    shrink ¶

    shrink :: proc(ba: ^Bit_Array) {…}
     

    Shrinks 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, #any_int index: uint) -> bool {…}
     

    Gets 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:
    true if bit is set

    unsafe_set ¶

    unsafe_set :: proc(ba: ^Bit_Array, bit: int) {…}
     

    Sets 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) {…}
     

    Unsets 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, #any_int index: uint, allocator := context.allocator) -> (ok: bool) {…}
     

    Unsets 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, false on allocation failure or bad index

    Procedure Groups

    This section is empty.

    Source Files

    Generation Information

    Generated with odin version dev-2024-12 (vendor "odin") Windows_amd64 @ 2024-12-20 21:10:45.845577400 +0000 UTC