nx_hash_index.nx
buildroot/runtime/nx_hash_index.nx
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
imports: nx_syscalls.nx
imported by: nx_hash_index_test.nxnx_physics_ladder.nx
structs
| none |
consts
| 10 | const HI_FNVP: i64 = 1099511628211 |
functions
| 12 | func 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 } |
| 13 | func 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 } |
| 16 | func hi_new(nbuckets: i64) -> *i64 |
| 26 | func hi_put(h: *i64, kptr: *u8, klen: i64, val: i64) -> i64 |
| 40 | func hi_get(h: *i64, kptr: *u8, klen: i64) -> i64 |