code wiki / _hdl_build / nx_eco_rooted_set.nx

nx_eco_rooted_set.nx source

↩ module page · 89 lines · 5047 B

1// nx_eco_rooted_set.nx -- emit the FROM-GOD ROOTED-SET: every organ traceable to the god component of the 2// family graph (the architect/genealogist's graph query that feeds HR's access plane, nx_hr_graph_access). 3// Rooted = undirected-connected to god (the max-fan-in node) = NOT an [I] island. This is the SSOT projection 4// "what has provenance": HR may assign access only to names in this set (provenance outranks authority). 5// Read-only over the eco_graph store (does NOT rebuild it, does NOT edit the sibling's honesty tool -- it 6// replicates the exact god-component BFS honesty uses, as a standalone emitter). stdout = one rooted name 7// per line (a clean rooted-set file); stderr = the count summary. 8// Optional 2nd arg = island-out-file: also emit the UN-rooted islands (the true-orphan worklist, provenance- 9// grounded) -- the janitor/architect's precise sprawl rock. This DISAMBIGUATES "orphan": a true island 10// (undirected-disconnected from god) is un-rooted; a childless-but-imported organ is rooted (has provenance, 11// just no descendants). The classifier's inflated orphan count conflates the two; THIS counts only true islands. 12// nx_eco_rooted_set <store-prefix> [island-out-file] license_tier: ORIGINAL module: nishi-core.architect.rooted_set 13import "nx_syscalls.nx" 14import "nx_eco_graph.nx" 15 16func rs_e(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(2, s, n); return 0 } 17func rs_en(v: i64) -> i64 { 18 let b: *u8 = sys_mmap(24); var m: i64 = v; if m < 0 { sys_write(2, "-" as *u8, 1); m = 0 - m } 19 let t: *u8 = sys_mmap(24); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } 20 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 21 var i: i64 = 0; while i < k { b[i] = t[k-1-i]; i = i + 1 } sys_write(2, b, k); return 0 22} 23 24func main(argc: i64, argv: *i64) -> i64 { 25 if argc < 2 { rs_e("usage: nx_eco_rooted_set <store-prefix>\n" as *u8); return 2 } 26 let g: *EcoGraph = eg_load(argv[1] as *u8) 27 if (g as i64) == 0 { rs_e("nx_eco_rooted_set: store load failed\n" as *u8); return 1 } 28 let n: i64 = g.node_count 29 if n <= 0 { rs_e("nx_eco_rooted_set: empty graph\n" as *u8); return 1 } 30 // god = max in-degree node (the same anchor honesty uses) 31 var god: i64 = 0 32 var i: i64 = 0 33 while i < n { if (g.in_head[i+1] - g.in_head[i]) > (g.in_head[god+1] - g.in_head[god]) { god = i } i = i + 1 } 34 // undirected DFS marking the god component 35 let vis: *u8 = sys_mmap(n + 2) 36 i = 0; while i < n { vis[i] = 0 as u8; i = i + 1 } 37 let stk: *i64 = sys_mmap((n + 2) * 8) as *i64 38 var sp: i64 = 0 39 stk[0] = god 40 vis[god] = 1 as u8 41 while sp >= 0 { 42 let v: i64 = stk[sp] 43 sp = sp - 1 44 var p: i64 = g.in_head[v] 45 while p < g.in_head[v+1] { let w: i64 = g.in_list[p]; if vis[w] == (0 as u8) { vis[w] = 1 as u8; sp = sp + 1; stk[sp] = w } p = p + 1 } 46 p = g.out_head[v] 47 while p < g.out_head[v+1] { let w2: i64 = g.out_list[p]; if vis[w2] == (0 as u8) { vis[w2] = 1 as u8; sp = sp + 1; stk[sp] = w2 } p = p + 1 } 48 } 49 // emit rooted names (stdout, clean) + summary (stderr) 50 var rooted: i64 = 0 51 i = 0 52 while i < n { 53 if vis[i] == (1 as u8) { 54 let off: i64 = g.node_off[i] 55 var ln: i64 = 0 56 while g.arena[off + ln] != (0 as u8) { ln = ln + 1 } 57 // emit the LOGICAL capability name (strip a trailing ".nx" -- access objects are logical, not files) 58 if ln > 3 { if g.arena[off+ln-3]==(46 as u8) { if g.arena[off+ln-2]==(110 as u8) { if g.arena[off+ln-1]==(120 as u8) { ln = ln - 3 } } } } 59 sys_write(1, ((g.arena as i64) + off) as *u8, ln) 60 sys_write(1, "\n" as *u8, 1) 61 rooted = rooted + 1 62 } 63 i = i + 1 64 } 65 // optional: emit the un-rooted islands (true-orphan worklist) to a companion file 66 if argc >= 3 { 67 let ipath: *u8 = argv[2] as *u8 68 let ifd: i64 = sys_openat_wr(ipath, 420) 69 if ifd >= 0 { 70 var isl: i64 = 0 71 i = 0 72 while i < n { 73 if vis[i] == (0 as u8) { 74 let ioff: i64 = g.node_off[i] 75 var iln: i64 = 0 76 while g.arena[ioff + iln] != (0 as u8) { iln = iln + 1 } 77 sys_write(ifd, ((g.arena as i64) + ioff) as *u8, iln) 78 sys_write(ifd, "\n" as *u8, 1) 79 isl = isl + 1 80 } 81 i = i + 1 82 } 83 sys_close(ifd) 84 rs_e("island-set: " as *u8); rs_en(isl); rs_e(" true un-rooted islands written (the provenance-grounded orphan-retire worklist)\n" as *u8) 85 } 86 } 87 rs_e("rooted-set: " as *u8); rs_en(rooted); rs_e(" of " as *u8); rs_en(n); rs_e(" organs are from-god-rooted (" as *u8); rs_en(n - rooted); rs_e(" un-rooted islands = ungrantable). NOTE: true-islands != the classifier's inflated orphan count (which also counts rooted-but-childless organs -- those HAVE provenance).\n" as *u8) 88 return 0 89}