code wiki / (root) / bitset.nx

bitset.nx

buildroot/runtime/bitset.nx

5376 B185 linesdepth 3pulls 3 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

syscalls.nx bitset.nx

imports: 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 bitset_set bitset_get bitset_count bitset_popcount_word bitset_clear bitset_union bitset_intersect

structs

33struct Bitset {

consts

none

functions

40func bitset_new(n: i64) -> *Bitset {
called by 1: main
56func bitset_set(bs: *Bitset, i: i64) -> i64 {
called by 1: main
64func bitset_clear(bs: *Bitset, i: i64) -> i64 {
called by 1: main
73func bitset_get(bs: *Bitset, i: i64) -> i64 {
called by 1: main
81func bitset_popcount_word(x: i64) -> i64 {
called by 1: bitset_count
92func bitset_count(bs: *Bitset) -> i64 {
called by 1: main calls 1: bitset_popcount_word
103func bitset_union(dst: *Bitset, src: *Bitset) -> i64 {
called by 1: main
114func bitset_intersect(dst: *Bitset, src: *Bitset) -> i64 {
called by 1: main
125func bitset_equal(a: *Bitset, b: *Bitset) -> i64 {
136func bitset_zero(bs: *Bitset) -> i64 {
146func main() -> i64 {