code wiki / (root) / nx_hash.nx

nx_hash.nx

buildroot/runtime/nx_hash.nx

6868 B202 linesdepth 3pulls 3 transitivereach 106 importersview sourcekind tooltopic hash
docsdependenciesstructsconstsfunctions

about

nx_hash.nx -- open-addressing hash table (linear probing, fnv-1a). FOUNDATION primitive. Any code that needs O(1) lookup uses this: * Symbol table during link * String interning in lex * Deduplication in opt * Visited-set in graph algorithms Today every NishiLang module that needs lookup either does linear scan or builds an ad-hoc table. Centralising removes ~hundred lines of repeated code across the runtime. Algorithm: open-addressing with linear probing. Power-of-two capacity for fast modulo (mask = cap - 1). Hash via FNV-1a (Fowler-Noll-Vo, public domain, well-distributed). Load factor: caller-controlled; resize is a TODO (v0.0.1 expects caller to size the table appropriately). API: nx_hash_new(cap_pow2) -- construct nx_hash_put(t, key, val) -- insert / overwrite nx_hash_get(t, key) -- lookup; -1 = not found nx_hash_has(t, key) -- 1 = present nx_hash_count(t) -- number of entries Keys are i64 (use the FNV-1a hash); values are i64. String interning users compute the FNV-1a of their string and use that as the i64 key.

dependencies 1 imports · 6 importers

syscalls.nx nx_hash.nx nx_frame_hash.nx nx_hash_kat.nx nx_intern.nx nx_set.nx nx_stl.nx nx_verify_ingest.nx

imports: syscalls.nx

imported by: nx_frame_hash.nxnx_hash_kat.nxnx_intern.nxnx_set.nxnx_stl.nxnx_verify_ingest.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_hash_new nx_hash_count nx_hash_has nx_hash_probe nx_hash_fnv1a_i64 nx_hash_get nx_hash_probe ↻ nx_hash_put nx_hash_probe ↻ nx_hash_fnv1a_i64 ↻ nx_hash_fnv1a_bytes

structs

76struct NxHash

consts

38const NX_MAGIC_1490: i64 = 1490
42const NX_HASH_FNV_OFFSET: i64 = 0xCBF29CE484222325
43const NX_HASH_FNV_PRIME: i64 = 0x100000001B3
73const NX_HASH_EMPTY: i64 = 0
74const NX_HASH_TOMBSTONE: i64 = -1
84const NX_HASH_BYTES: i64 = 40

functions

45func nx_hash_fnv1a_bytes(buf: *u8, len: i64) -> i64
57func nx_hash_fnv1a_i64(x: i64) -> i64
called by 2: nx_hash_probemain
86func nx_hash_new(cap_pow2: i64) -> *NxHash
103func nx_hash_probe(t: *NxHash, key: i64) -> i64
118func nx_hash_put(t: *NxHash, key: i64, val: i64) -> i64
128func nx_hash_get(t: *NxHash, key: i64) -> i64
136func nx_hash_has(t: *NxHash, key: i64) -> i64
143func nx_hash_count(t: *NxHash) -> i64 { return t.n }
called by 2: mainnx_set_count
147func main() -> i64