nx_bitset.nx
buildroot/runtime/nx_bitset.nx
about
bitset.nx -- packed bit array with O(1) get / set / clear.
Stores N boolean flags in ceil(N/64) i64 words. 8x denser
than bool[] (which nxc stores as i64 per element). Used for:
- SSA liveness (each block × each variable)
- garbage-collection mark bits (one bit per object)
- compiler dominance-frontier frontier sets
- simple set<i64> for small universes (port/file-descriptor tables)
- bloom filter internals (bitset + k hashes)
Not a drop-in Set<K> -- that's what map.nx is for. Bitset is
for dense bit-vectors where the universe is bounded and small.
Operations:
bitset_new(n) allocate n-bit bitset (all zeros)
bitset_set(bs, i) set bit i
bitset_clear(bs, i) clear bit i
bitset_get(bs, i) read bit i (0 or 1)
bitset_count(bs) popcount over all bits
bitset_union(dst, src) dst |= src, same capacity
bitset_intersect(dst, src) dst &= src
bitset_equal(a, b) byte-exact compare
Invariants:
BS1 bitset_new zeros the backing store -- no uninit reads.
BS2 get/set do NOT bounds-check (hot path); caller ensures
i < capacity. Debug wrapper could add that.
BS3 All *_in-place ops require both bitsets to share the
same capacity (word count).
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 39 | struct Bitset |
consts
| none |
functions
| 46 | func bitset_new(n: i64) -> *Bitset |
| 62 | func bitset_set(bs: *Bitset, i: i64) -> i64 called by 1: main |
| 70 | func bitset_clear(bs: *Bitset, i: i64) -> i64 called by 1: main |
| 79 | func bitset_get(bs: *Bitset, i: i64) -> i64 called by 1: main |
| 87 | func bitset_popcount_word(x: i64) -> i64 called by 1: bitset_count |
| 98 | func bitset_count(bs: *Bitset) -> i64 |
| 109 | func bitset_union(dst: *Bitset, src: *Bitset) -> i64 called by 1: main |
| 120 | func bitset_intersect(dst: *Bitset, src: *Bitset) -> i64 called by 1: main |
| 131 | func bitset_equal(a: *Bitset, b: *Bitset) -> i64 |
| 142 | func bitset_zero(bs: *Bitset) -> i64 |
| 152 | func main() -> i64 |