A bitset for operating on flags.
More...
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
|
|
typedef struct Bitset | Bitset |
| | A bitset spread across multiple uint32_t words.
|
| |
A bitset for operating on flags.
Definition in file bitset.h.
◆ BITSET_ARRAY_SIZE
| #define BITSET_ARRAY_SIZE 8 |
Number of words in a bitset.
Number of words in every bitset. This represents the maximum number and each bitset will always use this number of words, though it's capacity can be any length from 1 to BITSET_BITS_PER_WORD * BITSET_ARRAY_SIZE
Definition at line 28 of file bitset.h.
◆ BITSET_BITS_PER_WORD
| #define BITSET_BITS_PER_WORD 32 |
Number of bits in a word for a bitset.
Number of bits in a word for a bitset. Will always be 32 here.
Definition at line 18 of file bitset.h.
◆ BITSET_DEFINE
| #define BITSET_DEFINE |
( |
|
name, |
|
|
|
capacity |
|
) |
| |
Value:
.cap = capacity, \
};
#define BITSET_ARRAY_SIZE
Number of words in a bitset.
#define BITSET_BITS_PER_WORD
Number of bits in a word for a bitset.
A bitset spread across multiple uint32_t words.
uint32_t nbits
Number of bits in a word, will be 32.
uint32_t * w
Word array of uint32_t to hold the bitset data.
Make a standard bitset.
Make a bitset with a valid static array to store it's array of words.
Use this to define bitsets in the code, specifically as a static scoped variable. The passed name will be the same name as the bitset.
Usage example:
void bitset_clear(Bitset *bitset)
Clear the bitset, all to 0.
#define BITSET_DEFINE(name, capacity)
Make a standard bitset.
- Parameters
-
| name | the name of the bitset |
| capacity | the capacity of the bitset |
Definition at line 198 of file bitset.h.
◆ BITSET_MAX_BITS
Maximum number of bits in a bitset.
Definition at line 34 of file bitset.h.
◆ bitset_clear()
| void bitset_clear |
( |
Bitset * |
bitset | ) |
|
Clear the bitset, all to 0.
- Parameters
-
Definition at line 54 of file bitset.c.
◆ bitset_find_idx_of_nth_set()
| int bitset_find_idx_of_nth_set |
( |
const Bitset * |
bitset, |
|
|
int |
n |
|
) |
| |
Find the index of the nth set bit.
Find the index of the nth flag set to 1. This function is useful to get one value quickly, but does not operate iteratively well. Use a @BitsetItr for iterative access to a bitset.
- Parameters
-
- Returns
- The index of the nth flag set to
1 in the bitset
Definition at line 92 of file bitset.c.
◆ bitset_get_idx()
| bool bitset_get_idx |
( |
Bitset * |
bitset, |
|
|
int |
idx |
|
) |
| |
Get the value of a flag.
- Parameters
-
| bitset | A Bitset to operate on |
| idx | the index of the flag to get |
- Returns
- the value of the flag as
true or false
Definition at line 72 of file bitset.c.
◆ bitset_is_empty()
| bool bitset_is_empty |
( |
Bitset * |
bitset | ) |
|
Check if a bitset is empty (all 0's)
- Parameters
-
- Returns
true if empty, false otherwise
Definition at line 62 of file bitset.c.
◆ bitset_itr_create()
◆ bitset_itr_next()
Get the index of the next set bit in the bitset from a BitsetItr.
- Parameters
-
- Returns
- a positive number if successful, UNDEFINED otherwise (out-of-bounds)
Definition at line 140 of file bitset.c.
◆ bitset_num_set_bits()
| int bitset_num_set_bits |
( |
Bitset * |
bitset | ) |
|
Count how many bits are set to 1 in a bitset.
- Parameters
-
- Returns
- The number of flags set to
1 in a bitset
Definition at line 80 of file bitset.c.
◆ bitset_set_idx()
| void bitset_set_idx |
( |
Bitset * |
bitset, |
|
|
int |
idx, |
|
|
bool |
on |
|
) |
| |
Set a flag in a bitset to a value.
- Parameters
-
| bitset | A Bitset to operate on |
| idx | the index of the flag to set |
| on | the value to set the flag to |
Definition at line 5 of file bitset.c.
◆ bitset_set_next_free_idx()
| int bitset_set_next_free_idx |
( |
Bitset * |
bitset | ) |
|
Set the next free index in the bitset and return the index value.
- Parameters
-
- Returns
- The index of the bit that was set
Definition at line 27 of file bitset.c.