Loading...
Searching...
No Matches
fixed_bitset

Simple fixed-size bitset implementation. More...

Data Structures

struct  fixed_bitset_t
 Base type for a fixed-size bitset. More...
 

Macros

#define fixed_bitset_type(N)
 Macro used to define a fixed-size bitset of a given size.
 
#define fixed_bitset_with_fill(type, N, fill)   ({ type bitset; fixed_bitset_init(&bitset, type, N, fill); bitset; })
 Macro used to create a bitset with all bits set to a value.
 
#define fixed_bitset_init(ptr, type, N, fill)
 Initialize a bitset.
 

Functions

static uint fixed_bitset_size (const fixed_bitset_t *bitset)
 Get the size of the bitset.
 
static uint fixed_bitset_word_size (const fixed_bitset_t *bitset)
 Get the size of the bitset in words.
 
static void check_fixed_bitset (__unused const fixed_bitset_t *bitset)
 Check that the bitset is valid.
 
static fixed_bitset_tfixed_bitset_write_word (fixed_bitset_t *bitset, uint word_num, uint32_t value)
 Write a word in the bitset.
 
static uint32_t fixed_bitset_read_word (const fixed_bitset_t *bitset, uint word_num)
 Read a word in the bitset.
 
static fixed_bitset_tfixed_bitset_clear_all (fixed_bitset_t *bitset)
 Clear all bits in the bitset.
 
static fixed_bitset_tfixed_bitset_set_all (fixed_bitset_t *bitset)
 Set all bits in the bitset.
 
fixed_bitset_tfixed_bitset_flip_all (fixed_bitset_t *bitset)
 Flip all bits in the bitset.
 
bool fixed_bitset_is_empty (fixed_bitset_t *bitset)
 Determine if bitset is empty.
 
static fixed_bitset_tfixed_bitset_set (fixed_bitset_t *bitset, uint bit_index)
 Set a single bit in the bitset.
 
static fixed_bitset_tfixed_bitset_clear (fixed_bitset_t *bitset, uint bit_index)
 Clear a single bit in the bitset.
 
static fixed_bitset_tfixed_bitset_flip (fixed_bitset_t *bitset, uint bit_index)
 Flip a single bit in the bitset.
 
static bool fixed_bitset_get (const fixed_bitset_t *bitset, uint bit_index)
 Get the value of a single bit in the bitset.
 
static bool fixed_bitset_equal (const fixed_bitset_t *bitset1, const fixed_bitset_t *bitset2)
 Check if two bitsets are equal.
 

Detailed Description

Simple fixed-size bitset implementation.

Macro Definition Documentation

◆ fixed_bitset_init

#define fixed_bitset_init (   ptr,
  type,
  N,
  fill 
)
Value:
({ \
assert(sizeof(type) == fixed_bitset_sizeof_for(N)); \
__unused type *type_check = ptr; \
(ptr)->bitset.size = N; \
(ptr)->bitset.word_size = ((N) + 31u) / 32u; \
__builtin_memset(&(ptr)->bitset.words, (fill) ? 0xff : 0, (ptr)->bitset.word_size * sizeof(uint32_t)); \
})
uint16_t word_size
Number of 32-bit words used to store the bits.
Definition fixed_bitset.h:31
uint16_t size
Number of bits in the bitset.
Definition fixed_bitset.h:30
uint32_t words[]
Storage array for the bitset words.
Definition fixed_bitset.h:32

Initialize a bitset.

Parameters
ptrthe bitset to initialize
typethe type of the bitset
Nthe number of bits in the bitset
fillthe value to fill the bitset with (0 or 1)

◆ fixed_bitset_type

#define fixed_bitset_type (   N)
Value:
union { \
fixed_bitset_t bitset; \
struct { \
uint16_t size; \
uint16_t word_size; \
uint32_t words[((N) + 31) / 32]; \
} sized_bitset; \
}
Base type for a fixed-size bitset.
Definition fixed_bitset.h:29

Macro used to define a fixed-size bitset of a given size.

This macro is used to declare the type of a fixed-size bitset. It is used as follows:

typedef fixed_bitset_type(17) my_bitset_t;
#define fixed_bitset_type(N)
Macro used to define a fixed-size bitset of a given size.
Definition fixed_bitset.h:48

will define a new bitset type called my_bitset_t that can hold 17 boolean values.

The type can be used as my_bitset_t bitset; to declare a new bitset.

Parameters
Nthe number of boolean values in the bitset

◆ fixed_bitset_with_fill

#define fixed_bitset_with_fill (   type,
  N,
  fill 
)    ({ type bitset; fixed_bitset_init(&bitset, type, N, fill); bitset; })

Macro used to create a bitset with all bits set to a value.

Parameters
typethe type of the bitset
Nthe number of bits in the bitset
fillthe value to set the bits to (0 or 1)
Returns
the bitset

Function Documentation

◆ check_fixed_bitset()

static void check_fixed_bitset ( __unused const fixed_bitset_t bitset)
inlinestatic

Check that the bitset is valid.

This function will assert if the bitset is not valid.

Parameters
bitsetthe bitset to check

◆ fixed_bitset_clear()

static fixed_bitset_t * fixed_bitset_clear ( fixed_bitset_t bitset,
uint  bit_index 
)
inlinestatic

Clear a single bit in the bitset.

Parameters
bitsetthe bitset
bit_indexthe bit to clear
Returns
the bitset

◆ fixed_bitset_clear_all()

static fixed_bitset_t * fixed_bitset_clear_all ( fixed_bitset_t bitset)
inlinestatic

Clear all bits in the bitset.

Parameters
bitsetthe bitset
Returns
the bitset

◆ fixed_bitset_equal()

static bool fixed_bitset_equal ( const fixed_bitset_t bitset1,
const fixed_bitset_t bitset2 
)
inlinestatic

Check if two bitsets are equal.

Parameters
bitset1the first bitset to check
bitset2the second bitset to check
Returns
true if the bitsets are equal, false otherwise

◆ fixed_bitset_flip()

static fixed_bitset_t * fixed_bitset_flip ( fixed_bitset_t bitset,
uint  bit_index 
)
inlinestatic

Flip a single bit in the bitset.

Parameters
bitsetthe bitset
bit_indexthe bit to flip
Returns
the bitset

◆ fixed_bitset_flip_all()

fixed_bitset_t * fixed_bitset_flip_all ( fixed_bitset_t bitset)

Flip all bits in the bitset.

Parameters
bitsetthe bitset
Returns
the bitset

◆ fixed_bitset_get()

static bool fixed_bitset_get ( const fixed_bitset_t bitset,
uint  bit_index 
)
inlinestatic

Get the value of a single bit in the bitset.

Parameters
bitsetthe bitset
bit_indexthe bit to get the value of
Returns
the value of the bit

◆ fixed_bitset_is_empty()

bool fixed_bitset_is_empty ( fixed_bitset_t bitset)

Determine if bitset is empty.

Parameters
bitsetthe bitset
Returns
true if not bits are set

◆ fixed_bitset_read_word()

static uint32_t fixed_bitset_read_word ( const fixed_bitset_t bitset,
uint  word_num 
)
inlinestatic

Read a word in the bitset.

Parameters
bitsetthe bitset
word_numthe word number to read from
Returns
the value of the word

◆ fixed_bitset_set()

static fixed_bitset_t * fixed_bitset_set ( fixed_bitset_t bitset,
uint  bit_index 
)
inlinestatic

Set a single bit in the bitset.

Parameters
bitsetthe bitset
bit_indexthe bit to set
Returns
the bitset

◆ fixed_bitset_set_all()

static fixed_bitset_t * fixed_bitset_set_all ( fixed_bitset_t bitset)
inlinestatic

Set all bits in the bitset.

Parameters
bitsetthe bitset
Returns
the bitset

◆ fixed_bitset_size()

static uint fixed_bitset_size ( const fixed_bitset_t bitset)
inlinestatic

Get the size of the bitset.

Parameters
bitsetthe bitset to get the size of
Returns
the size of the bitset

◆ fixed_bitset_word_size()

static uint fixed_bitset_word_size ( const fixed_bitset_t bitset)
inlinestatic

Get the size of the bitset in words.

Parameters
bitsetthe bitset to get the size of
Returns
the size of the bitset in words

◆ fixed_bitset_write_word()

static fixed_bitset_t * fixed_bitset_write_word ( fixed_bitset_t bitset,
uint  word_num,
uint32_t  value 
)
inlinestatic

Write a word in the bitset.

Parameters
bitsetthe bitset to write to
word_numthe word number to write to
valuethe value to write to the word
Returns
the bitset