code wiki / _hdl_build / nx_reader_census_store.nx
nx_reader_census_store.nx source
↩ module page · 54 lines · 2420 B
1// nx_reader_census_store.nx -- LIB: the reader S-class CENSUS in the SOVEREIGN seg-store (knowledge/store/rcen-*,
2// via nx_seg_store) -- operator 2026-06-21: "stop using tsv, we are nishi ecosystem hardware-rung-up". The
3// machine-matchable home for the reader capability census, replacing reader_sclass_capability_target.tsv. NO TSV.
4// Record schema (keys under prefix rcen-), TAB-separated value fields (tabs are the VALUE encoding inside the
5// content-addressed store blob, NOT a .tsv file):
6// rc:ids -> index: TAB-separated list of capability ids (the walk order)
7// rc:<id> -> id <tab> tier <tab> dimension <tab> capability <tab> best_in_class <tab> status <tab> exceed_angle
8// license_tier: ORIGINAL
9import "nx_seg_store.nx"
10import "nx_syscalls.nx"
11
12const RC_PREFIX: *u8 = "knowledge/store/rcen-"
13
14func rc_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
15// latest record for key: 1=found (ptr/len set), 0=tombstoned, -1=absent.
16func rc_get(key: *u8, ptrout: *i64, lenout: *i64) -> i64 { return ss_get(RC_PREFIX, key, ptrout, lenout) }
17// next segment id for a commit = 1 + current segment count.
18func rc_seg_next_p(prefix: *u8) -> i64 {
19 let segs: *i64 = sys_mmap(8 * 260) as *i64
20 let nseg: i64 = ss_manifest(prefix, segs)
21 if nseg < 0 { return 1 }
22 return 1 + nseg
23}
24// extract the f-th (0-based) TAB-separated field of rec[0..rlen) into out (NUL-terminated); returns field length.
25func rc_field(rec: *u8, rlen: i64, f: i64, out: *u8) -> i64 {
26 var cur: i64 = 0
27 var i: i64 = 0
28 var o: i64 = 0
29 while cur < f {
30 if i >= rlen { out[0] = 0 as u8; return 0 }
31 if rec[i] == (9 as u8) { cur = cur + 1 }
32 i = i + 1
33 }
34 var go: i64 = 1
35 while go == 1 {
36 if i >= rlen { go = 0 } else {
37 if rec[i] == (9 as u8) { go = 0 } else { out[o] = rec[i]; o = o + 1; i = i + 1 }
38 }
39 }
40 out[o] = 0 as u8
41 return o
42}
43// 1 if the store's current value for key byte-equals val[0..vlen). Drives idempotent skip + post-commit verify.
44func rc_streq_store(key: *u8, val: *u8, vlen: i64) -> i64 {
45 let pq: *i64 = sys_mmap(16) as *i64
46 let lq: *i64 = sys_mmap(16) as *i64
47 if rc_get(key, pq, lq) != 1 { return 0 }
48 let b: *u8 = pq[0] as *u8
49 let n: i64 = lq[0]
50 if n != vlen { return 0 }
51 var i: i64 = 0
52 while i < n { if b[i] != val[i] { return 0 } i = i + 1 }
53 return 1
54}