Design decisions

110. CSR Adj<V, A> for pair/triple graphs and zero-copy array-to-list lowering (2026-11-21)

  • Decision. Return a compressed sparse row struct Adj<V, A> (start: List<0..=2_000_000_000>, arcs: List<A>, with out/get/deg) from Graph.directed/Graph.undirected on plain pair/triple lists (directed_of_pairs, undirected_of_pairs, directed_of_triples, undirected_of_triples) instead of [V]List<...>, narrow Graph<V, E>.start to List<0..=2_000_000_000>, preserve element narrowing through Builtin::Copy and Builtin::ListFilled, lower 1D array arguments in list_form via List(edges) (Builtin::ArrayToList, zero-copy) rather than a [each cell for each cell in edges] copy loop, and pre-allocate order with unchecked: inner loops in Rooted.build/Rooted.finish.
  • Why. Graph.undirected(edges) on n = 10^6 vertices previously allocated n separate std::vector<int> adjacency lists plus a 16 MB temporary edge-list copy, leaving bench/trees/root_bench at 0.35–0.41 s / 121–124 MB (1.52x time, 1.77x memory vs hand C++ 0.29 s / 69.8 MB). CSR Adj, zero-copy ArrayToList, narrowing start/at through Copy/ListFilled, and pre-allocated Rooted BFS bring root_bench to 0.22 s / 79.8 MB (0.76x time, 1.14x memory vs hand C++).
  • Reverse. Change directed_of_pairs/undirected_of_pairs/directed_of_triples/undirected_of_triples in stdlib/graph.cp back to [V]List<...> and remove Adj<V, A>.