Bitstring

Bitstring utility. More...

Modules

Types
Bitstring data types.

Functions

gos_result_t gos_bitstring_alloc ( gos_bitstring_t **bitstring_ptr, uint32_t bit_count)
gos_result_t gos_bitstring_init ( gos_bitstring_t *bitstring, uint32_t bit_count)
gos_result_t gos_bitstring_reset ( gos_bitstring_t *bitstring)
uint32_t gos_bitstring_get_count (const gos_bitstring_t *bitstring)
gos_result_t gos_bitstring_set_bit ( gos_bitstring_t *bitstring, uint32_t bit_index)
gos_result_t gos_bitstring_clear_bit ( gos_bitstring_t *bitstring, uint32_t bit_index)
bool gos_bitstring_bit_is_set (const gos_bitstring_t *bitstring, uint32_t bit_index)
uint32_t gos_bitstring_get_index (const gos_bitstring_t *bitstring, uint32_t nth_set_bit)
void gos_bitstring_merge ( gos_bitstring_t *dest_bitstring, const gos_bitstring_t *src_bitstring, bool set_bits)
gos_result_t gos_bitstring_iterator_init ( gos_bitstring_iterator_t *iterator, const gos_bitstring_t *bitstring)
uint32_t gos_bitstring_iterator_current (const gos_bitstring_iterator_t *iterator)
uint32_t gos_bitstring_iterator_next ( gos_bitstring_iterator_t *iterator)

Detailed Description

Bitstring utility.

Function Documentation

gos_bitstring_alloc()

gos_result_t gos_bitstring_alloc ( gos_bitstring_t ** bitstring_ptr,
uint32_t bit_count
)

Allocate a gos_bitstring_t object

Note
Use gos_free() to cleanup the allocated object
Parameters
bitstring_ptr Pointer to hold allocated object
bit_count Number of bits this string can hold
Returns
gos_result_t , result of API call

gos_bitstring_bit_is_set()

bool gos_bitstring_bit_is_set ( const gos_bitstring_t * bitstring,
uint32_t bit_index
)

Return if bit at index is set to 1

Parameters
bitstring gos_bitstring_t to check bit
bit_index Index of bit to return if it is set to 1
Returns
true if bit a bit_index is 1, false else

gos_bitstring_clear_bit()

gos_result_t gos_bitstring_clear_bit ( gos_bitstring_t * bitstring,
uint32_t bit_index
)

Clear bit to 0 at specified index

Parameters
bitstring gos_bitstring_t to clear bit in
bit_index Index of bit in string to clear to 0
Returns
gos_result_t , result of API call

gos_bitstring_get_count()

uint32_t gos_bitstring_get_count ( const gos_bitstring_t * bitstring )

Return the number of bits set to 1 in the bitstring

Parameters
bitstring gos_bitstring_t to get count
Returns
Number of bits set to 1 in provided gos_bitstring_t

gos_bitstring_get_index()

uint32_t gos_bitstring_get_index ( const gos_bitstring_t * bitstring,
uint32_t nth_set_bit
)

Return index of nth set bit in string

This returns the index of the nth set it in the given gos_bitstring_t

Parameters
bitstring gos_bitstring_t to iterate
nth_set_bit Number of set bits to count
Returns
The index of the nth_set_bit in the given bitstring

gos_bitstring_init()

gos_result_t gos_bitstring_init ( gos_bitstring_t * bitstring,
uint32_t bit_count
)

Initialize a pre-allocated gos_bitstring_t object

Parameters
bitstring Pointer to pre-allocated gos_bitstring_t object
bit_count Number of bits this string can hold
Returns
gos_result_t , result of API call

gos_bitstring_iterator_current()

uint32_t gos_bitstring_iterator_current ( const gos_bitstring_iterator_t * iterator )

Get the current index of the iterator

This returns the current index of the given iterator . If the iterator has gone past all the SET bits in the bitstring then this will return UINT16_MAX.

Note
gos_bitstring_iterator_init() but be called first.
Parameters
iterator Iterator to get current index
Returns
Current index of iterator

gos_bitstring_iterator_init()

gos_result_t gos_bitstring_iterator_init ( gos_bitstring_iterator_t * iterator,
const gos_bitstring_t * bitstring
)

Initialize a gos_bitstring_iterator_t

This initializes a gos_bitstring_iterator_t which is used to iterate over the set bits in the specified bitstring.

Parameters
iterator gos_bitstring_iterator_t to initialize
bitstring gos_bitstring_t to iterate
Returns
gos_result_t , result of API call

gos_bitstring_iterator_next()

uint32_t gos_bitstring_iterator_next ( gos_bitstring_iterator_t * iterator )

Get index of next SET bit of bitstring

This finds the next SET bit of the corresponding bitstring and returns its index in the string. If no more SET bits are found then this return UINT16_MAX.

Note
gos_bitstring_iterator_init() but be called first.
Parameters
iterator Iterator to find next SET bit in bitstring
Returns
Index of next SET bit in bitstring

gos_bitstring_merge()

void gos_bitstring_merge ( gos_bitstring_t * dest_bitstring,
const gos_bitstring_t * src_bitstring,
bool set_bits
)

Merge bitstrings

Merge the bits in src_bitstring into dest_bitstring . If set_bits = true, then all the set bits in src_bitstring while be set in dest_bitstring . If set_bits = false, then all the cleared bits in src_bitstring while be cleared in dest_bitstring .

Note
The given src_bitstring and dest_bitstring` do NOT need to be the same length.
Parameters
dest_bitstring String to update
src_bitstring String to merge into dest_bitstring
set_bits If true then set corresponding bits in dest_bitstring (e.g. OR operation), if false then clear corresponding bits in dest_bitstring (e.g. AND operation)

gos_bitstring_reset()

gos_result_t gos_bitstring_reset ( gos_bitstring_t * bitstring )

Clear all bits to zero

This clears all bits in the given gos_bitstring_t to zero.

Parameters
bitstring gos_bitstring_t to clear to zero
Returns
gos_result_t , result of API call

gos_bitstring_set_bit()

gos_result_t gos_bitstring_set_bit ( gos_bitstring_t * bitstring,
uint32_t bit_index
)

Set bit to 1 at specified index

Parameters
bitstring gos_bitstring_t to set bit in
bit_index Index of bit in string to set to 1
Returns
gos_result_t , result of API call