19 bitset->
w[i] |= (uint32_t)1 << b;
23 bitset->
w[i] &= ~((uint32_t)1 << b);
29 for (uint32_t i = 0; i < bitset->
nwords; i++)
31 uint32_t inv = ~bitset->w[i];
44 int bit = __builtin_ctz(inv);
45 bitset->
w[i] |= ((uint32_t)1 << bit);
47 return (idx < bitset->cap) ? idx : UNDEFINED;
56 for (
int i = 0; i < bitset->
nwords; i++)
64 for (
int i = 0; i < bitset->
nwords; i++)
77 return bitset->
w[i] & (uint32_t)1 << b;
84 for (
int i = 0; i < bitset->
nwords; i++)
86 sum += __builtin_popcount(bitset->
w[i]);
97 for (
int i = 0; i < bitset->
nwords; i++)
99 tracker += __builtin_popcount(bitset->
w[i]);
106 int base = prev_tracker - 1;
108 int offset = bitset->
nbits * i;
109 for (
int j = 0; j < bitset->
nbits; j++)
115 base += (bitset->
w[i] >> j) & 0x01;
122 prev_tracker = tracker;
A bitset for operating on flags.
bool bitset_get_idx(Bitset *bitset, int idx)
Get the value of a flag.
bool bitset_is_empty(Bitset *bitset)
Check if a bitset is empty (all 0's)
void bitset_clear(Bitset *bitset)
Clear the bitset, all to 0.
int bitset_num_set_bits(Bitset *bitset)
Count how many bits are set to 1 in a bitset.
int bitset_find_idx_of_nth_set(const Bitset *bitset, int n)
Find the index of the nth set bit.
#define BITSET_BITS_PER_WORD
Number of bits in a word for a bitset.
int bitset_set_next_free_idx(Bitset *bitset)
Set the next free index in the bitset and return the index value.
BitsetItr bitset_itr_create(const Bitset *bitset)
Declare a BitsetItr.
int bitset_itr_next(BitsetItr *itr)
Get the index of the next set bit in the bitset from a BitsetItr.
void bitset_set_idx(Bitset *bitset, int idx, bool on)
Set a flag in a bitset to a value.
An iterator into a Bitset.
int bit
Current bit the iterator is on.
int word
Current word the iterator is on.
int itr
Number of bits that have been iterated through in total.
const Bitset * bitset
Bitset this is iterating through
A bitset spread across multiple uint32_t words.
uint32_t nbits
Number of bits in a word, will be 32.
uint32_t nwords
Number of words int the w array.
uint32_t * w
Word array of uint32_t to hold the bitset data.
Utilities relating around number string representation and protected arithmatic helper functions.