147. Constructor ownership; trees on one Rooted; DFS (2026-11-21)
- Constructors (agreed). R5 applies: parameters lend for the call,
the result is owned unless the signature says
lends. Stdlib rule: a result owns its data when copying it fits the documented cost; it lends only when copying would cost more than building (O(1) views and adapters). SoLcaTable(t),Lift(t, ...),Centroids(t),t.virtual(keys)own their tables and leavetfree;lendsin a signature always reads "O(1), borrows". Sharing a domain (t.Pre) is a type, not a lend. Written into 05-ownership.md §5. Why: an earlier reply saidLcaTable(t)"lendst", and Ryan asked when that became policy; owned results can be returned, stored besidet, or outlive it. Reverse: let derived structures storetand declarelends(t). - Trees (agreed).
Rootedis the one static tree. Everything on it uses only its O(n) build (parent, depth, size, children, heavy-light,t.Pre), so many methods are fine; anything costing more time or memory is its own owned structure built explicitly:LcaTable(t)(O(1) LCA),Lift(t, val, op:)(path fold for any op,climb_while),Centroids(t),t.virtual(keys), and range structures overt.Pre. LCA onRootedis heavy-light, O(log n), O(n) memory (speed not benchmarked yet).JumpTreestays for trees growing by leaves;LinkCut,EulerTourTreefor changing trees.Rooted(g: Next<V>, root:)replacesnew(next, root, w:); weighted depth comes from.weighted(f). Ryan: "for the most part i'm pretty aligned with what you've described ... i trust you to go on and figure that out" (the exact surface is delegated). - DFS (agreed, same message).
step.prune()afterEnter; events carry the arc,Enter(v, via: ?Arc),Exit(v, via: ?Arc); anAgain(from, via)event for arcs into visited vertices; optional sharedseen: mut [V]Bool; freereachable(g, from:)with noskip:;g.dfs_tree(root)returns(tree: Rooted, tree_edge: [E]Bool), andDfsTreegoes. Reverse: the oldEnter/Exit-onlyVisit. - Queued. Rewrite
spec/std/tree.cp, the DFS parts ofgraph.cpand the tree section of graphs-trees.md to this; trimRootedagainst the dreams.