code wiki / (root) / nx_bitset.nx

nx_bitset.nx

buildroot/runtime/nx_bitset.nx

5445 B191 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_bitset.nx

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

main bitset_new sys_mmap bitset_set bitset_get bitset_count bitset_popcount_word bitset_clear bitset_union bitset_intersect

structs

39struct Bitset

consts

none

functions

46func bitset_new(n: i64) -> *Bitset
called by 1: main calls 1: sys_mmap
62func bitset_set(bs: *Bitset, i: i64) -> i64
called by 1: main
70func bitset_clear(bs: *Bitset, i: i64) -> i64
called by 1: main
79func bitset_get(bs: *Bitset, i: i64) -> i64
called by 1: main
87func bitset_popcount_word(x: i64) -> i64
called by 1: bitset_count
98func bitset_count(bs: *Bitset) -> i64
called by 1: main calls 1: bitset_popcount_word
109func bitset_union(dst: *Bitset, src: *Bitset) -> i64
called by 1: main
120func bitset_intersect(dst: *Bitset, src: *Bitset) -> i64
called by 1: main
131func bitset_equal(a: *Bitset, b: *Bitset) -> i64
142func bitset_zero(bs: *Bitset) -> i64
152func main() -> i64