Documentation

CslibFrontier.DataStructure.SearchTree.PointerMachine.Child

Replacing a linked child #

replaceChild lifts a separately represented replacement subtree into its original parent. The replacement is separated from its parent and sibling and frames every record outside the original child; one pointer update restores the whole linked-tree representation.

def Cslib.DataStructure.SearchTree.PointerMachine.nodeAt {M : PointerMachine.Model} {extra : ℕ} (right : Bool) (label : Label M extra) (child sibling : BinaryTree (Label M extra)) :
BinaryTree (Label M extra)

Place a distinguished child on the selected side of a linked parent.

theorem Cslib.DataStructure.SearchTree.PointerMachine.nodeAt_addresses {M : PointerMachine.Model} {extra : ℕ} (right : Bool) (label : Label M extra) (child sibling : BinaryTree (Label M extra)) :
addresses (nodeAt right label child sibling) = Insert.insert label.address (addresses child ∪ addresses sibling)

The parent contributes one address alongside its child and sibling.

theorem Cslib.DataStructure.SearchTree.PointerMachine.nodeAt_distinct_iff {M : PointerMachine.Model} {extra : ℕ} (right : Bool) (label : Label M extra) (child sibling : BinaryTree (Label M extra)) :
AddressesDistinct (nodeAt right label child sibling) ↔ AddressesDistinct child ∧ AddressesDistinct sibling ∧ label.address ∉ addresses child ∧ label.address ∉ addresses sibling ∧ Disjoint (addresses child) (addresses sibling)

Separation of a child, its sibling, and their parent.

theorem Cslib.DataStructure.SearchTree.PointerMachine.represents_nodeAt_iff {M : PointerMachine.Model} {extra regs : ℕ} (right : Bool) (h : List (PointerMachine.Record M (layout extra regs))) (parent : PointerMachine.Pointer) (label : Label M extra) (child sibling : BinaryTree (Label M extra)) :
Represents h parent (nodeAt right label child sibling) ↔ h[label.address]? = some (record (if right = true then root sibling else root child) (if right = true then root child else root sibling) parent label) ∧ Represents h (some label.address) child ∧ Represents h (some label.address) sibling

The representation of a node whose distinguished child is on the selected side.

@[simp]
theorem Cslib.DataStructure.SearchTree.PointerMachine.root_nodeAt {M : PointerMachine.Model} {extra : ℕ} (right : Bool) (label : Label M extra) (child sibling : BinaryTree (Label M extra)) :
root (nodeAt right label child sibling) = some label.address

The root of a node is its label, whichever side its distinguished child is on.

The root of a tree is one of its addresses.

theorem Cslib.DataStructure.SearchTree.PointerMachine.Represents.congr_addresses {M : PointerMachine.Model} {extra regs : ℕ} {h k : List (PointerMachine.Record M (layout extra regs))} {t : BinaryTree (Label M extra)} {parent : PointerMachine.Pointer} (rep : Represents h parent t) (agree : ∀ z ∈ addresses t, k[z]? = h[z]?) :
Represents k parent t

Agreement on the addresses of a tree transports its representation.

theorem Cslib.DataStructure.SearchTree.PointerMachine.nodeAt_not {M : PointerMachine.Model} {extra : ℕ} (right : Bool) (label : Label M extra) (child sibling : BinaryTree (Label M extra)) :
nodeAt (!right) label sibling child = nodeAt right label child sibling

Exchanging the side and the two subtrees gives the same node.

theorem Cslib.DataStructure.SearchTree.PointerMachine.Represents.nodeAt_congr_child {M : PointerMachine.Model} {extra regs : ℕ} (right : Bool) {h k : List (PointerMachine.Record M (layout extra regs))} {label : Label M extra} {child child' sibling : BinaryTree (Label M extra)} {parent : PointerMachine.Pointer} (rep : Represents h parent (nodeAt right label child sibling)) (rep' : Represents k (some label.address) child') (same : root child' = root child) (outside : ∀ z ∉ addresses child, k[z]? = h[z]?) (nl : label.address ∉ addresses child) (dis : Disjoint (addresses child) (addresses sibling)) :
Represents k parent (nodeAt right label child' sibling)

Replacing the distinguished child of a node by a tree with the same root, in a heap that agrees outside the old child, keeps the node represented.

theorem Cslib.DataStructure.SearchTree.PointerMachine.replaceChild {M : PointerMachine.Model} {extra regs : ℕ} (right : Bool) (h k : List (PointerMachine.Record M (layout extra regs))) (label : Label M extra) (old new sibling : BinaryTree (Label M extra)) (parent : PointerMachine.Pointer) (rep : Represents h parent (nodeAt right label old sibling)) (distinct : AddressesDistinct (nodeAt right label old sibling)) (newRep : Represents k (some label.address) new) (newDistinct : AddressesDistinct new) (newRoot : label.address ∉ addresses new) (newSibling : Disjoint (addresses new) (addresses sibling)) (frame : ∀ z ∉ addresses old, k[z]? = h[z]?) :
have heap := k.modify label.address fun (n : PointerMachine.Record M (layout extra regs)) => { ptr := Function.update n.ptr (if right = true then 1 else 0) (root new), data := n.data }; Represents heap parent (nodeAt right label new sibling) ∧ AddressesDistinct (nodeAt right label new sibling) ∧ ∀ z ∉ addresses (nodeAt right label old sibling), heap[z]? = h[z]?

Reconnect a replacement child separated from its parent and sibling. Updating the parent link preserves the sibling, global address separation, and all external records.