Simple fixed-size bitset implementation.
More...
Simple fixed-size bitset implementation.
◆ 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
-
| ptr | the bitset to initialize |
| type | the type of the bitset |
| N | the number of bits in the bitset |
| fill | the value to fill the bitset with (0 or 1) |
◆ fixed_bitset_type
| #define fixed_bitset_type |
( |
|
N | ) |
|
Value: union { \
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:
#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
-
| N | the 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
-
| type | the type of the bitset |
| N | the number of bits in the bitset |
| fill | the value to set the bits to (0 or 1) |
- Returns
- the bitset
◆ 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
-
| bitset | the bitset to check |
◆ fixed_bitset_clear()
Clear a single bit in the bitset.
- Parameters
-
| bitset | the bitset |
| bit_index | the bit to clear |
- Returns
- the bitset
◆ fixed_bitset_clear_all()
Clear all bits in the bitset.
- Parameters
-
- Returns
- the bitset
◆ fixed_bitset_equal()
Check if two bitsets are equal.
- Parameters
-
| bitset1 | the first bitset to check |
| bitset2 | the second bitset to check |
- Returns
- true if the bitsets are equal, false otherwise
◆ fixed_bitset_flip()
Flip a single bit in the bitset.
- Parameters
-
| bitset | the bitset |
| bit_index | the bit to flip |
- Returns
- the bitset
◆ fixed_bitset_flip_all()
Flip all bits in the bitset.
- Parameters
-
- 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
-
| bitset | the bitset |
| bit_index | the bit to get the value of |
- Returns
- the value of the bit
◆ fixed_bitset_is_empty()
Determine if bitset is empty.
- Parameters
-
- 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
-
| bitset | the bitset |
| word_num | the word number to read from |
- Returns
- the value of the word
◆ fixed_bitset_set()
Set a single bit in the bitset.
- Parameters
-
| bitset | the bitset |
| bit_index | the bit to set |
- Returns
- the bitset
◆ fixed_bitset_set_all()
Set all bits in the bitset.
- Parameters
-
- Returns
- the bitset
◆ fixed_bitset_size()
Get the size of the bitset.
- Parameters
-
| bitset | the bitset to get the size of |
- Returns
- the size of the bitset
◆ fixed_bitset_word_size()
Get the size of the bitset in words.
- Parameters
-
| bitset | the bitset to get the size of |
- Returns
- the size of the bitset in words
◆ fixed_bitset_write_word()
Write a word in the bitset.
- Parameters
-
| bitset | the bitset to write to |
| word_num | the word number to write to |
| value | the value to write to the word |
- Returns
- the bitset