code wiki / (root) / nx_planescan.nx

nx_planescan.nx

buildroot/runtime/nx_planescan.nx

12232 B238 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_planescan.nx -- SOVEREIGN SCALABLE PLANE ENUMERATION (the storage-foundation primitive). THE GAP (measured 2026-07-24): seg-store planes written by nx_sqlite_rows carry NO ids-index, so a plane is fetchable ONLY by exact key -- you cannot count, list, or search it. And the naive workaround (loop ss_get over guessed keys) LEAKS ~O(segments) mmaps per call (ss_get returns pointers INTO each segment's mmap and never frees them) -> ~87k maps on a 93-seg plane -> vm.max_map_count crash (filed seq750). This is the leak-free primitive: read the manifest, map EACH segment .docs exactly ONCE, walk its records in memory, munmap it. O(total-bytes) time, O(1) resident, ~1 mmap per segment (all freed). Record framing = [kind:u8][klen:u32be][key][vlen:u32be][val] (ss_w32 big-endian); every offset bounded to the mapping. Turns every plane into something you can count / search / paginate at scale. Importable (no main besides selftest). Also the CANONICAL home of the hardened NXR1 field reader (was 3 copies; seq751). license_tier: ORIGINAL Read-only over the plane, no hw writes (Rule 26).

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_seg_store.nx nx_planescan.nx

imports: nx_syscalls.nxnx_seg_store.nx

imported by: nobody (leaf or entry point)

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

main ps_eq ps_selftest sys_mmap ps_nxr1_field ps_len ps_r32 ps_puts sys_write sys_mkdir sys_unlinkat ss_begin ss_begin_cap sys_mmap ↻ ss_add ss_add2 ss_w32 ss_len ss_commit ss_segid_ok sys_mmap ↻ ss_cat ss_catn sys_mmap ↻ sys_write ↻ ss_write_seg ss_segid_ok ↻ sys_mmap ↻ ss_cat ↻ ss_catn ↻ sys_write ↻ ss_segname ss_cat ↻ ss_catn ↻ ss_writefile sys_openat_wr sys_write ↻ sys_close sys_fsync sys_renameat

structs

none

consts

16const PS_MAGIC_1024: i64 = 1024
17const PS_MAGIC_4096: i64 = 4096
74const PS_OP_COUNT: i64 = 0
75const PS_OP_FIND: i64 = 1

functions

19func ps_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
20func ps_cat(d: *u8, o: i64, s: *u8) -> i64 { var p: i64=o; var i: i64=0; while s[i]!=(0 as u8){ d[p]=s[i]; p=p+1; i=i+1 } return p }
called by 1: ps_scan
21func ps_r32(p: *u8, o: i64) -> i64 { let a: i64=p[o]; let b: i64=p[o+1]; let c: i64=p[o+2]; let d: i64=p[o+3]; return (((((a<<8)|b)<<8)|c)<<8)|d }
22func ps_eq(a: *u8, b: *u8) -> i64 { var i: i64=0; while 1==1 { if a[i]!=b[i] { return 0 } if a[i]==(0 as u8) { return 1 } i=i+1 } return 0 }
24func ps_key_has_prefix(key: *u8, kl: i64, prefix: *u8) -> i64
called by 1: ps_walk_seg calls 1: ps_len
34func ps_nxr1_field(rec: *u8, reclen: i64, key: *u8, out: *u8, maxout: i64) -> i64
called by 2: ps_walk_segps_selftest calls 2: ps_lenps_r32
79func ps_walk_seg(b: *u8, sz: i64, keyprefix: *u8, st: *i64) -> i64
127func ps_scan(prefix: *u8, keyprefix: *u8, st: *i64) -> i64
163func ps_count(prefix: *u8, keyprefix: *u8) -> i64
called by 2: ps_selftestmain calls 2: sys_mmapps_scan
171func ps_find_field(prefix: *u8, keyprefix: *u8, field: *u8, val: *u8, outbuf: *u8, outcap: i64, outkey: *u8) -> i64
called by 1: ps_selftest calls 2: sys_mmapps_scan
179func ps_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 2: ps_selftestmain calls 1: sys_write
180func ps_udec(v: i64) -> i64 { let d: *u8=sys_mmap(32); var m: i64=v; var k: i64=0; if m==0{d[0]=48;k=1}; let t: *u8=sys_mmap(32); while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var o: *u8=sys_mmap(32); var i: i64=0; while i<k{o[i]=t[k-1-i];i=i+1}; sys_write(1,o,k); return 0 }
called by 2: ps_selftestmain calls 2: sys_mmapsys_write
182func ps_selftest() -> i64
230func main(argc: i64, argv: *i64) -> i64