Skip to main content

Module shared_bit_vec

Module shared_bit_vec 

Source
Expand description

SharedBitVec - cross-process bit-packed boolean array.

Fixed-size bit array stored in an MMF. Each underlying u64 word is operated on atomically (fetch_or for set, fetch_and for clear) so concurrent writers don’t lose updates.

§Layout

+---------------------------+
| BitVecHeader (64B)        |
|   magic, capacity_bits    |
+---------------------------+
| words[ceil(cap/64)]       |  AtomicU64 each
+---------------------------+

§Concurrency

  • set(i) -> word.fetch_or(1 << bit, AcqRel). Multiple writers setting distinct bits in the same word compose correctly (RMW; no lost updates).
  • clear(i) -> word.fetch_and(!(1 << bit), AcqRel).
  • toggle(i) -> word.fetch_xor(1 << bit, AcqRel).
  • get(i) -> word.load(Acquire) & (1 << bit) != 0.
  • set_range(lo, hi) / clear_range(lo, hi) use RMW on boundary words and store on fully-covered interior words. Interior stores are safe because they overwrite all 64 bits; no concurrent writer can be modifying interior bits THIS call expects to keep (we’re setting/clearing them all).

§Use cases

  • Cross-process set membership (presence/absence flags).
  • Bloom filter backing array.
  • Allocation bitmaps (slot in use / free).
  • Feature flag arrays.
  • Multi-process work-stealing claim bits.

Structs§

BitVecHeader
SharedBitVec

Enums§

BitVecError

Constants§

BITS_PER_WORD
BITVEC_MAGIC

Functions§

bit_vec_file_size