Loading...
Searching...
No Matches
bit_array.h File Reference

Bit array data structure. More...

Functions

uint32_t spdk_bit_array_capacity (const struct spdk_bit_array *ba)
 Return the number of bits that a bit array is currently sized to hold.
 
struct spdk_bit_array * spdk_bit_array_create (uint32_t num_bits)
 Create a bit array.
 
void spdk_bit_array_free (struct spdk_bit_array **bap)
 Free a bit array and set the pointer to NULL.
 
int spdk_bit_array_resize (struct spdk_bit_array **bap, uint32_t num_bits)
 Create or resize a bit array.
 
bool spdk_bit_array_get (const struct spdk_bit_array *ba, uint32_t bit_index)
 Get the value of a bit from the bit array.
 
int spdk_bit_array_set (struct spdk_bit_array *ba, uint32_t bit_index)
 Set (to 1) a bit in the bit array.
 
void spdk_bit_array_clear (struct spdk_bit_array *ba, uint32_t bit_index)
 Clear (to 0) a bit in the bit array.
 
uint32_t spdk_bit_array_find_first_set (const struct spdk_bit_array *ba, uint32_t start_bit_index)
 Find the index of the first set bit in the array.
 
uint32_t spdk_bit_array_find_first_clear (const struct spdk_bit_array *ba, uint32_t start_bit_index)
 Find the index of the first cleared bit in the array.
 
uint32_t spdk_bit_array_count_set (const struct spdk_bit_array *ba)
 Count the number of set bits in the array.
 
uint32_t spdk_bit_array_count_clear (const struct spdk_bit_array *ba)
 Count the number of cleared bits in the array.
 
void spdk_bit_array_store_mask (const struct spdk_bit_array *ba, void *mask)
 Store bitmask from bit array.
 
void spdk_bit_array_load_mask (struct spdk_bit_array *ba, const void *mask)
 Load bitmask to bit array.
 
void spdk_bit_array_clear_mask (struct spdk_bit_array *ba)
 Clear (to 0) bit array bitmask.
 

Detailed Description

Bit array data structure.

Function Documentation

◆ spdk_bit_array_capacity()

uint32_t spdk_bit_array_capacity ( const struct spdk_bit_array * ba)

Return the number of bits that a bit array is currently sized to hold.

Parameters
baBit array to query.
Returns
the number of bits.

◆ spdk_bit_array_clear()

void spdk_bit_array_clear ( struct spdk_bit_array * ba,
uint32_t bit_index )

Clear (to 0) a bit in the bit array.

If bit_index is beyond the end of the bit array, no action is taken. Bits beyond the end of the bit array are implicitly 0.

Parameters
baBit array to clear a bit.
bit_indexThe index of a bit to clear.

◆ spdk_bit_array_clear_mask()

void spdk_bit_array_clear_mask ( struct spdk_bit_array * ba)

Clear (to 0) bit array bitmask.

Parameters
baBit array.

◆ spdk_bit_array_count_clear()

uint32_t spdk_bit_array_count_clear ( const struct spdk_bit_array * ba)

Count the number of cleared bits in the array.

Parameters
baThe bit array to search.
Returns
the number of bits cleared in the array.

◆ spdk_bit_array_count_set()

uint32_t spdk_bit_array_count_set ( const struct spdk_bit_array * ba)

Count the number of set bits in the array.

Parameters
baThe bit array to search.
Returns
the number of bits set in the array.

◆ spdk_bit_array_create()

struct spdk_bit_array * spdk_bit_array_create ( uint32_t num_bits)

Create a bit array.

Parameters
num_bitsNumber of bits that the bit array is sized to hold.

All bits in the array will be cleared.

Returns
a pointer to the new bit array.

◆ spdk_bit_array_find_first_clear()

uint32_t spdk_bit_array_find_first_clear ( const struct spdk_bit_array * ba,
uint32_t start_bit_index )

Find the index of the first cleared bit in the array.

Parameters
baThe bit array to search.
start_bit_indexThe bit index from which to start searching (0 to start from the beginning of the array).
Returns
the index of the first cleared bit. If no bits are cleared, returns UINT32_MAX.

◆ spdk_bit_array_find_first_set()

uint32_t spdk_bit_array_find_first_set ( const struct spdk_bit_array * ba,
uint32_t start_bit_index )

Find the index of the first set bit in the array.

Parameters
baThe bit array to search.
start_bit_indexThe bit index from which to start searching (0 to start from the beginning of the array).
Returns
the index of the first set bit. If no bits are set, returns UINT32_MAX.

◆ spdk_bit_array_free()

void spdk_bit_array_free ( struct spdk_bit_array ** bap)

Free a bit array and set the pointer to NULL.

Parameters
bapBit array to free.

◆ spdk_bit_array_get()

bool spdk_bit_array_get ( const struct spdk_bit_array * ba,
uint32_t bit_index )

Get the value of a bit from the bit array.

If bit_index is beyond the end of the current size of the bit array, this function will return false (i.e. bits beyond the end of the array are implicitly 0).

Parameters
baBit array to query.
bit_indexThe index of a bit to query.
Returns
the value of a bit from the bit array on success, or false on failure.

◆ spdk_bit_array_load_mask()

void spdk_bit_array_load_mask ( struct spdk_bit_array * ba,
const void * mask )

Load bitmask to bit array.

Parameters
baBit array.
maskSource mask. Mask and bit array capacity must be equal.

◆ spdk_bit_array_resize()

int spdk_bit_array_resize ( struct spdk_bit_array ** bap,
uint32_t num_bits )

Create or resize a bit array.

To create a new bit array, pass a pointer to a spdk_bit_array pointer that is NULL for bap.

The bit array will be sized to hold at least num_bits.

If num_bits is smaller than the previous size of the bit array, any data beyond the new num_bits size will be cleared.

If num_bits is larger than the previous size of the bit array, any data beyond the old num_bits size will be cleared.

Parameters
bapBit array to create/resize.
num_bitsNumber of bits that the bit array is sized to hold.
Returns
0 on success, negative errno on failure.

◆ spdk_bit_array_set()

int spdk_bit_array_set ( struct spdk_bit_array * ba,
uint32_t bit_index )

Set (to 1) a bit in the bit array.

If bit_index is beyond the end of the bit array, this function will return -EINVAL.

Parameters
baBit array to set a bit.
bit_indexThe index of a bit to set.
Returns
0 on success, negative errno on failure.

◆ spdk_bit_array_store_mask()

void spdk_bit_array_store_mask ( const struct spdk_bit_array * ba,
void * mask )

Store bitmask from bit array.

Parameters
baBit array.
maskDestination mask. Mask and bit array capacity must be equal.