Documentation

CslibFrontier.DataStructure.SearchTree.PointerMachine.Graft

Attaching a fresh leaf inside a linked context #

graftLeaf validates the append-and-parent-update heap produced by leaf allocation. Freshness comes from the previous heap length, so no old node can alias the new record. The theorem reconstructs the whole linked tree, its address separation and exact footprint.

theorem Cslib.DataStructure.SearchTree.PointerMachine.graftLeaf {M : PointerMachine.Model} {extra regs : ℕ} (h : List (PointerMachine.Record M (layout extra regs))) (cs : List (Frame M extra)) (label : Label M extra) (side : Fin 2) (rep : Represents h none (plug cs BinaryTree.nil)) (distinct : AddressesDistinct (plug cs BinaryTree.nil)) (atEnd : label.address = h.length) (chosen : match cs, rep, distinct with | [], rep, distinct => True | Frame.left label right :: tail, rep, distinct => side = 0 | Frame.right left label :: tail, rep, distinct => side = 1) :
have extended := h ++ [record none none (contextParent cs) label]; have heap := match contextParent cs with | none => extended | some a => extended.modify a fun (n : PointerMachine.Record M (layout extra regs)) => { ptr := Function.update n.ptr side.castSucc (some label.address), data := n.data }; have tree := plug cs (BinaryTree.node label BinaryTree.nil BinaryTree.nil); Represents heap none tree ∧ AddressesDistinct tree ∧ addresses tree = Insert.insert label.address (addresses (plug cs BinaryTree.nil)) ∧ root tree = if contextParent cs = none then some label.address else root (plug cs BinaryTree.nil)

Appending at the old heap length and filling the context's vacant child link creates exactly the plugged fresh leaf. Existing addresses remain distinct; the root changes only for an empty context. The side agrees with the immediate ghost parent when one exists.