Documentation

CslibFrontier.DataStructure.SearchTree.PointerMachine.Allocation

Allocating linked tree nodes #

allocate creates a leaf with its parent from pointer register two and its scalar fields from supplied data registers. Its execution theorem charges allocation and every field store, preserves the entire old heap and all registers except cursor zero, and identifies the new leaf. Attaching the leaf to its parent and rebalancing are separate operations.

def Cslib.DataStructure.SearchTree.PointerMachine.allocate {M : PointerMachine.Model} {extra regs : ℕ} (source : Fin (extra + 1) → Fin (regs + 2)) :

Allocate a leaf in cursor register zero, initialize its parent from pointer register two, and copy each scalar field from the specified data register.

theorem Cslib.DataStructure.SearchTree.PointerMachine.allocate_correct {M : PointerMachine.Model} {extra regs : ℕ} (source : Fin (extra + 1) → Fin (regs + 2)) (x : PointerMachine.State M (layout extra regs)) (pc : x.pc = 0) :
have label := { address := x.heap.length, data := fun (f : Fin (extra + 1)) => x.data (source f) }; ∃ (y : PointerMachine.State M (layout extra regs)), PointerMachine.Executes (allocate source) x y (extra + 4) ∧ y.heap = x.heap ++ [record none none (x.ptr 2) label] ∧ y.ptr = Function.update x.ptr 0 (some x.heap.length) ∧ y.data = x.data ∧ Represents y.heap (x.ptr 2) (BinaryTree.node label BinaryTree.nil BinaryTree.nil)

Allocation initializes all fields in exactly extra + 4 instructions, including halt. It appends exactly one record and preserves every register except cursor zero. The new node is a represented leaf, with the specified parent and complete scalar payload.