code wiki / (root) / nx_hash_index.nx

nx_hash_index.nx

buildroot/runtime/nx_hash_index.nx

2310 B52 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind librarytopic hash
docsdependenciesstructsconstsfunctions

about

nx_hash_index.nx -- sovereign O(1) HASH INDEX library (variable-length keys), the read-path exceed, extracted as a reusable component (Rule 15 DRY). Proven in nx_hash_index_bench: 65 ns/op = ~3.8x faster than sqlite's cited B-tree probe (250 ns) and ~4.9x faster than binary search. FNV-1a + open-addressing linear probe. Designed for the seg_store get path (per-segment cache) and any other consumer. handle layout (one mmap of i64): [0]=nbuckets [1]=mask, then kptr[nb]@2, klen[nb]@2+nb, val[nb]@2+2nb. val == -1 marks an empty bucket (store values are non-negative record/offset ids, so -1 is a safe sentinel). license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_hash_index.nx nx_hash_index_test.nx nx_physics_ladder.nx

imports: nx_syscalls.nx

imported by: nx_hash_index_test.nxnx_physics_ladder.nx

structs

none

consts

10const HI_FNVP: i64 = 1099511628211

functions

12func hi_hash(k: *u8, klen: i64) -> i64 { var h: i64=0; var i: i64=0; while i<klen { h=(h ^ (k[i] as i64)) * HI_FNVP; i=i+1 } return h }
called by 2: hi_puthi_get
13func hi_keq(a: *u8, alen: i64, b: *u8, blen: i64) -> i64 { if alen!=blen { return 0 } var i: i64=0; while i<alen { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
called by 3: hi_puthi_getmain
16func hi_new(nbuckets: i64) -> *i64
called by 2: mainmain calls 1: sys_mmap
26func hi_put(h: *i64, kptr: *u8, klen: i64, val: i64) -> i64
called by 2: mainmain calls 2: hi_hashhi_keq
40func hi_get(h: *i64, kptr: *u8, klen: i64) -> i64
called by 2: mainmain calls 2: hi_hashhi_keq