Module: collections.bitset
Source: ./collections/bitset.reef
Overview
collections/bitset - Efficient Bit Set Data Structure
Provides memory-efficient storage and manipulation of boolean flags. Uses 64-bit integers as storage (1 bit per flag vs 8 bits for bool).
Collections 0.9.2 / D12. BitSet stays a NON-GENERIC struct -- its width is fixed at create(n) and it holds bits, not values, so there is nothing to parameterise. It is method-based now; the free functions and their bit_ / _bit affixes are gone, because the receiver is already a BitSet.
Usage: import collections.bitset
let bs = bitset.create(256) // 256-bit bitset bs.set(10) bs.set(42)
if bs.test(10) println("Bit 10 is set") end if
print("Count: ") print_int(bs.count()) println("")
Renamed with the free functions (D12): set_bit -> set, clear_bit -> clear, toggle_bit -> toggle, test_bit -> test, count_set -> count, first_set_bit -> first_set, next_set_bit -> next_set, and the allocating bit_union / bit_intersection / bit_difference / bit_xor lose the bit_ prefix. The in-place *_into forms keep their names.
An out-of-range bit index remains a NO-OP rather than an error, which is the behaviour callers already relied on.
Use Cases:
- Compiler type qualifiers (const, volatile, etc.)
- Visited node tracking in graph traversal
- Sparse set membership testing
- Feature flag management
Types
BitSet
Fields:
| Name | Type |
|---|---|
words |
[int] |
num_words |
int |
num_bits |
int |
Functions
fn bits_per_word(): int
Bits per word (using 32-bit for portability) Note: Reef's int is 64-bit but overflow occurs at 32 bits in multiplication
fn words_needed(n: int): int
Calculate number of words needed for n bits
fn create(size: int): BitSet
fn create_64(): BitSet
fn create_256(): BitSet
fn create_1024(): BitSet
fn word_index(n: int): int
Get word index for bit n
fn bit_position(n: int): int
Get bit position within word
fn bit_mask(pos: int): int
Create a mask with bit at position set Note: For 64-bit integers, positions 0-63 are valid
Generated by reefc doc