13 #define BITSET_WORD_MAX (UCHAR_MAX)
14 #define WORD_SIZE (sizeof(bitset_word_t) * CHAR_BIT)
17 static size_t word_index(
size_t bit)
23 static size_t word_offset(
size_t bit)
37 return bitset_start(set) + index;
59 for (
size_t i = word_index(start); i < set.words; i++)
66 size_t offset = word_offset(start);
67 for (
size_t j = offset; j <
WORD_SIZE; j++)
69 if ((word & (1 << j)) == 0)
84 size_t words =
CT_MIN(set.words, mask.words);
89 for (
size_t i = 0; i < words; i++)
91 if ((data[i] & mask_data[i]) != 0)
102 size_t words =
CT_MIN(set.words, mask.words);
107 for (
size_t i = 0; i < words; i++)
109 if ((data[i] & mask_data[i]) != mask_data[i])
122 size_t word = word_index(index);
123 size_t offset = word_offset(index);
125 return (*word_at(set, word) & (1 << offset)) != 0;
132 size_t word = word_index(index);
133 size_t offset = word_offset(index);
135 *word_at(set, word) |= (1 << offset);
142 size_t word = word_index(index);
143 size_t offset = word_offset(index);
145 *word_at(set, word) &= ~(1 << offset);
unsigned char bitset_word_t
STA_DECL bitset_t bitset_of(void *data, size_t words)
#define STA_DECL
sal2 annotation on function implementations to copy annotations from the declaration
CT_NOALIAS CT_BASE_API void ctu_memset(STA_WRITES(size) void *dst, int value, size_t size)
set memory to a value equivalent to memset but with safety checks
size_t bitset_len(bitset_t set)
get the number of bits in a bitset
bool bitset_test(bitset_t set, size_t index)
test if a bit is set
bool bitset_any(bitset_t set, bitset_t mask)
test if any bits in a given mask are set
STA_DECL size_t bitset_set_first(bitset_t set, size_t start)
scan for the next free bit and set it
void bitset_reset(bitset_t set)
reset all bits in a bitset
bool bitset_all(bitset_t set, bitset_t mask)
test if all bits in a given mask are set
void bitset_set(bitset_t set, size_t index)
set a bit
void bitset_clear(bitset_t set, size_t index)
clear a bit
#define CTASSERT(expr)
assert a condition, prints the condition as a message
#define CTASSERTF(expr,...)
assert a condition with a message and optional format arguments