Documentation

CslibFrontier.DataStructure.SearchTree.PointerMachine.Update

Scalar updates in linked trees #

A scalar store updates the represented node's field without changing any links or registers. The ghost tree records the same update at every occurrence of that address; no separation hypothesis is needed. Updating a non-key field preserves the entire key tree. This supplies payload and cached-metadata writes for a mutable dictionary, not AVL rebalancing.

def Cslib.DataStructure.SearchTree.PointerMachine.updateData {M : PointerMachine.Model} {extra : ℕ} (t : BinaryTree (Label M extra)) (a : ℕ) (field : Fin (extra + 1)) (value : M.Value) :
BinaryTree (Label M extra)

Update one scalar field at a ghost address, retaining all addresses and links.

theorem Cslib.DataStructure.SearchTree.PointerMachine.root_updateData {M : PointerMachine.Model} {extra : ℕ} (t : BinaryTree (Label M extra)) (a : ℕ) (field : Fin (extra + 1)) (value : M.Value) :
root (updateData t a field value) = root t

Scalar-field updates preserve the root pointer.

theorem Cslib.DataStructure.SearchTree.PointerMachine.keys_updateData {M : PointerMachine.Model} {extra : ℕ} (t : BinaryTree (Label M extra)) (a : ℕ) (field : Fin (extra + 1)) (value : M.Value) (notKey : field ≠ 0) :
keys (updateData t a field value) = keys t

Payload or metadata writes leave the key tree unchanged.

theorem Cslib.DataStructure.SearchTree.PointerMachine.Represents.updateData {M : PointerMachine.Model} {extra regs : ℕ} {heap : List (PointerMachine.Record M (layout extra regs))} {parent : PointerMachine.Pointer} {t : BinaryTree (Label M extra)} (rep : Represents heap parent t) (a : ℕ) (field : Fin (extra + 1)) (value : M.Value) :
Represents (heap.modify a fun (n : PointerMachine.Record M (layout extra regs)) => { ptr := n.ptr, data := Function.update n.data field value }) parent (PointerMachine.updateData t a field value)

A heap scalar write implements the corresponding ghost-tree update.

theorem Cslib.DataStructure.SearchTree.PointerMachine.storeData_correct {M : PointerMachine.Model} {extra regs : ℕ} (x : PointerMachine.State M (layout extra regs)) (t : BinaryTree (Label M extra)) (parent : PointerMachine.Pointer) (rep : Represents x.heap parent t) (base : Fin 7) (a : ℕ) (cursor : x.ptr base = some a) (field : Fin (extra + 1)) (src : Fin (regs + 2)) (pc : x.pc = 0) :
∃ (y : PointerMachine.State M (layout extra regs)), PointerMachine.Executes [PointerMachine.Instr.storeData field base src, PointerMachine.Instr.halt] x y 2 ∧ Represents y.heap parent (updateData t a field (x.data src)) ∧ y.ptr = x.ptr ∧ y.data = x.data ∧ y.heap.length = x.heap.length ∧ ∀ (b : ℕ), b ≠ a → y.heap[b]? = x.heap[b]?

A store followed by halt takes two instructions, preserves all registers and links, and updates exactly the selected field in the represented tree. The base register may designate a node anywhere in the tree (or an unrelated record).

theorem Cslib.DataStructure.SearchTree.PointerMachine.updateData_eq_self {M : PointerMachine.Model} {extra : ℕ} (tree : BinaryTree (Label M extra)) (a : ℕ) (field : Fin (extra + 1)) (value : M.Value) (fresh : ∀ (p : PosNum) (u : Label M extra), BinaryTree.get p tree = some u → u.address ≠ a) :
updateData tree a field value = tree

A scalar write outside a tree leaves that ghost tree unchanged.

@[simp]
theorem Cslib.DataStructure.SearchTree.PointerMachine.addresses_updateData {M : PointerMachine.Model} {extra : ℕ} (tree : BinaryTree (Label M extra)) (a : ℕ) (field : Fin (extra + 1)) (value : M.Value) :
addresses (updateData tree a field value) = addresses tree

Scalar-field writes preserve the complete node-address footprint.

theorem Cslib.DataStructure.SearchTree.PointerMachine.AddressesDistinct.updateData {M : PointerMachine.Model} {extra : ℕ} {tree : BinaryTree (Label M extra)} (h : AddressesDistinct tree) (a : ℕ) (field : Fin (extra + 1)) (value : M.Value) :

Scalar-field updates preserve the separation of node addresses.