Public C API for the BitVector data structure. More...


Go to the source code of this file.
Classes | |
| struct | BitVector |
| Packed bit array with rank-support structures. More... | |
Macros | |
| #define | BV_ALIGN 64 |
| Alignment (in bytes) for all BitVector allocations. | |
| #define | BV_WORDS_SUPER_SHIFT 3 |
| Log2 of the number of 64‑bit words per superblock. | |
| #define | BV_WORDS_SUPER (1u << BV_WORDS_SUPER_SHIFT) |
| Number of 64-bit worde in a superblock. | |
Functions | |
| BitVector * | bv_new (size_t n_bits) |
| Allocate a new BitVector with all bits cleared. | |
| BitVector * | bv_copy (const BitVector *src) |
| Make a copy of an existing BitVector. | |
| void | bv_free (BitVector *bv) |
| Free all memory associated with a BitVector. | |
| void | bv_set_range (BitVector *bv, size_t start, size_t len) |
| Set all bits in the half-open range [start, start+len). | |
| void | bv_clear_range (BitVector *bv, size_t start, size_t len) |
| Clear all bits in the half-open range [start, start+len). | |
| void | bv_flip_range (BitVector *bv, size_t start, size_t len) |
| Toggle (flip) all bits in the half-open range [start, start+len). | |
| void | bv_build_rank (BitVector *bv) |
| Build or rebuild the rank tables for a BitVector. | |
| size_t | bv_rank (BitVector *bv, const size_t pos) |
| Compute the rank (number of set bits) up to a position. | |
| bool | bv_equal (const BitVector *a, const BitVector *b) |
| Test equality of two BitVectors. | |
| bool | bv_contains_subvector (const BitVector *a, const BitVector *b) |
| Check weather B appears as a contiguous sub-bitvector of A. | |
| int | bv_get (const BitVector *bv, const size_t pos) |
| Get the bit value at a given position. | |
| void | bv_set (BitVector *bv, const size_t pos) |
| Set the bit at a given position (set to 1) | |
| void | bv_clear (BitVector *bv, const size_t pos) |
| Clear the bit at a given position (set to 0) | |
| void | bv_flip (BitVector *bv, const size_t pos) |
| Toggle (flip) the bit at a given position. | |
| BitVector * | bv_concat (const BitVector *a, const BitVector *b) |
| Concatenate two BitVectors into a new BitVector. | |
| BitVector * | bv_repeat (const BitVector *bv, const size_t count) |
Repeat a BitVector n times. | |
Public C API for the BitVector data structure.
Declares the stable, external-facing API for working with BitVectors:
The public API is intentionally minimal. Internal helpers, inline fast‑paths, and low‑level utilities are defined separately in bitvector_internal.h.
BitVector provides a compact, cache‑friendly bit array with optional auxiliary rank tables enabling O(1) prefix‑popcount queries.
| #define BV_ALIGN 64 |
Alignment (in bytes) for all BitVector allocations.
Ensures that the underlying word array is aligned for efficient SIMD and cache‑line access.
| #define BV_WORDS_SUPER_SHIFT 3 |
Log2 of the number of 64‑bit words per superblock.
Used to compute superblock indices via bit‑shifts rather than division.
| void bv_build_rank | ( | BitVector * | bv | ) |
| void bv_clear | ( | BitVector * | bv, |
| const size_t | pos | ||
| ) |
Clear the bit at a given position (set to 0)
Marks the rank table dirty so it will be rebuilt on next rank query.
| bv | Pointer to the BitVector |
| pos | Bit index |
| void bv_clear_range | ( | BitVector * | bv, |
| size_t | start, | ||
| size_t | len | ||
| ) |
Clear all bits in the half-open range [start, start+len).
Marks the rank table dirty so it will be rebuilt on next rank query.
| bv | Pointer to the BitVector |
| start | Start bit index |
| len | Number of bits to clear |
| void bv_flip | ( | BitVector * | bv, |
| const size_t | pos | ||
| ) |
Toggle (flip) the bit at a given position.
Marks the rank table dirty so it will be rebuilt on next rank query.
| bv | Pointer to the BitVector |
| pos | Bit index |
| void bv_flip_range | ( | BitVector * | bv, |
| size_t | start, | ||
| size_t | len | ||
| ) |
Toggle (flip) all bits in the half-open range [start, start+len).
Marks the rank table dirty so it will be rebuilt on next rank query.
| bv | Pointer to the BitVector |
| start | Start bit index |
| len | Number of bits to flip |
| void bv_free | ( | BitVector * | bv | ) |
| int bv_get | ( | const BitVector * | bv, |
| const size_t | pos | ||
| ) |
Get the bit value at a given position.
| bv | Pointer to the BitVector |
| pos | Bit index |
0 or 1 depending on the bit value | BitVector * bv_new | ( | size_t | n_bits | ) |
| size_t bv_rank | ( | BitVector * | bv, |
| const size_t | pos | ||
| ) |
Compute the rank (number of set bits) up to a position.
If the internal rank tables are dirty, they will be rebuilt.
| bv | Pointer to the BitVector |
| pos | Bit index |
[0...pos) | void bv_set | ( | BitVector * | bv, |
| const size_t | pos | ||
| ) |
Set the bit at a given position (set to 1)
Marks the rank table dirty so it will be rebuilt on next rank query.
| bv | Pointer to the BitVector |
| pos | Bit index |