code wiki / _hdl_build / nx_galx_cid_index.nx
nx_galx_cid_index.nx
buildroot/runtime/_hdl_build/nx_galx_cid_index.nx
about
nx_galx_cid_index.nx -- SOVEREIGN O(1) cid->path store (replaces the per-request flat-TSV scan).
The gallery resolved cid->path by READING + SCANNING the whole galx_cid_paths.tsv (34.5MB, 235k lines) on
EVERY /img and /thumb request -- a grid page = ~60 of those = the "loading is atrocious". This builds a
sovereign binary hash index (our own format, NOT a flat TSV; "nishi ecosystem all the way up"): an FNV-1a
open-addressed bucket table (cid_hash -> path location) + a paths blob. Lookup is O(1) average. The .idx +
.blob ARE the runtime store; the TSV is only a one-time build input (and can then be retired).
Format:
<idx>: [8 n_buckets][8 n_entries] then n_buckets * 24: [8 cid_hash][8 path_off][8 path_len]
cid_hash==0 marks an empty bucket (a cid hashing to 0 is remapped to 1).
<blob>: the concatenated path bytes (path_off/path_len locate each).
Collision-safety: FNV-1a 64; for 235k entries the chance of ANY 64-bit collision is ~3e-9 (negligible);
the cid itself is nxc1-<64 hex> (already a content hash) so it is effectively unique.
license_tier: ORIGINAL
dependencies 1 imports · 3 importers
imports: nx_syscalls.nx
imported by: nx_gallery_serve.nxnx_galx_cid_index_gate.nxnx_galx_cid_verify.nx
structs
| none |
consts
| 18 | const CIDX_CIDLEN: i64 = 69 // "nxc1-" + 64 hex |
functions
| 21 | func cidx_fnv1a(s: *u8, n: i64) -> i64 |
| 34 | func gs_cidindex_build(tsv_path: *u8, idx_path: *u8, blob_path: *u8) -> i64 |
| 92 | func cidx_rd64(p: *u8, o: i64) -> i64 { return ((p[o] as i64)<<56)|((p[o+1] as i64)<<48)|((p[o+2] as i64)<<40)|((p[o+3] as i64)<<32)|((p[o+4] as i64)<<24)|((p[o+5] as i64)<<16)|((p[o+6] as i64)<<8)|(p[o+7] as i64) } |
| 96 | func gs_cidindex_lookup(idx: *u8, blob: *u8, nb: i64, cid: *u8, out_path: *u8) -> i64 |