nx_dep_graph.nx
buildroot/runtime/hub/nx_dep_graph.nx
about
nx_dep_graph.nx -- V2.0 P-8: directed dependency graph + Tarjan SCC.
Sovereign port of Tarjan's 1972 strongly-connected-components algorithm
(Robert Tarjan, "Depth-first search and linear graph algorithms",
SIAM J. Computing, 1972). Linear-time O(V+E) cycle detection across
the substrate artifact graph.
COMPOSES (per "avoid duplicate primitives" cardinal):
nx_syscalls.sys_mmap (per-instance buffer allocation)
COMPOSED BY:
wiki/nx_pipeline_walker (V2.0 P-8.5; queued -- populates graph from
extractor_nx import lists)
wiki/nx_pipeline_route (V3+ /wiki/pipeline/graph view)
wiki/nx_artifact_store (V3+ MEANINGFUL refinement: artifact with
resolved imports + reverse-deps is more MEANINGFUL than orphans)
V2.0 P-8 SCOPE:
- NxDepGraph: parallel-pool adjacency list (from_rowid -> list of to_rowid)
- nx_dep_graph_add_edge: caller-driven population
- nx_dep_graph_tarjan_scc: iterative Tarjan SCC (NO recursion; substrate-
friendly; bounded stack budget per NX_DEPG_MAX_STACK)
- Per-rowid SCC ID assignment (scc_id[rowid] = scc index 0..N-1)
- Accessors: deps / reverse-deps / scc-of / scc-size / cycle-detection
V3+ SCOPE (TODO):
- Topological sort within DAG (sccs treated as supernodes)
- Critical-path computation (longest dep chain)
- Pretty-printed graphviz / mermaid emit
- Per-SCC quarantine recommendation (cycle = MEANINGFUL refinement
blocker per V2_0_PIPELINE_BOOTSTRAP ยง2.2)
REFERENCE: Tarjan 1972 -- the original DFS-based algorithm. Substrate
implementation uses explicit work-stack + index/lowlink arrays (no
recursive function calls).
Status: V2.0 P-8. 2026-05-27.
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_pipeline_graph_builder.nxnx_wiki_main.nx
structs
| 71 | struct NxDepGraph |
consts
| 42 | const NX_DEPG_OK: i64 = 0 |
| 43 | const NX_DEPG_BAD_INPUT: i64 = 3040 |
| 44 | const NX_DEPG_GRAPH_FULL: i64 = 3041 |
| 45 | const NX_DEPG_EDGE_FULL: i64 = 3042 |
| 46 | const NX_DEPG_STACK_OVERFLOW: i64 = 3043 |
| 47 | const NX_DEPG_NOT_BUILT: i64 = 3044 |
| 48 | const NX_DEPG_LOOP_BUDGET: i64 = 3045 |
| 49 | const NX_DEPG_OUT_OF_RANGE: i64 = 3046 |
| 52 | const NX_DEPG_HARD_MAX_NODES: i64 = 10000 |
| 53 | const NX_DEPG_HARD_MAX_EDGES: i64 = 100000 |
| 54 | const NX_DEPG_MAX_STACK: i64 = 10000 // Tarjan work-stack cap |
| 55 | const NX_DEPG_LOOP_BUDGET_CAP: i64 = 100000000 |
| 58 | const NX_DEPG_UNVISITED: i64 = 0 - 1 |
functions
| 102 | func nx_dep_graph_init(g: *NxDepGraph, nodes_cap: i64, edges_cap: i64) -> i64 calls 1: sys_mmap |
| 143 | func nx_dep_graph_add_edge(g: *NxDepGraph, from_rowid: i64, to_rowid: i64) -> i64 called by 1: nx_pipeline_build_dep_graph |
| 169 | func nx_dep_graph_tarjan_scc(g: *NxDepGraph) -> i64 |
| 299 | func nx_dep_graph_scc_of(g: *NxDepGraph, rowid: i64) -> i64 |
| 308 | func nx_dep_graph_scc_size(g: *NxDepGraph, rowid: i64) -> i64 |
| 325 | func nx_dep_graph_is_in_cycle(g: *NxDepGraph, rowid: i64) -> i64 calls 1: nx_dep_graph_scc_size |
| 332 | func nx_dep_graph_deps_count(g: *NxDepGraph, rowid: i64) -> i64 |
| 340 | func nx_dep_graph_dep_at(g: *NxDepGraph, from_rowid: i64, i: i64) -> i64 |
| 352 | func nx_dep_graph_rev_deps_count(g: *NxDepGraph, rowid: i64) -> i64 |
| 366 | func nx_dep_graph_scc_count(g: *NxDepGraph) -> i64 |
| 373 | func nx_dep_graph_edge_count(g: *NxDepGraph) -> i64 |
| 380 | func nx_dep_graph_count_nodes_in_cycles(g: *NxDepGraph) -> i64 calls 1: nx_dep_graph_scc_size |