Documentation

CslibFrontier.DataStructure.BTree.WordRAM.InsertLoop

Proactive Top-Down Non-Full Insertion Loop (insertLoop) #

Internal Word-RAM downward-pass loop used privately by Insert (never re-exported publicly by CslibFrontier.DataStructure.BTree.WordRAM): starting from any non-full node u (numKeys u ≤ 2 * t - 2), scans u, overwrites in place if k is already in u, shift-inserts if u is a leaf, or proactively splits a full child c via splitChildCode before descending (insertLoop, insertLoop_spec).

Downward proactive-split insertion loop over non-full nodes (while rZero < rActive).

theorem Cslib.DataStructure.BTree.WordRAM.insertLoop_spec {l w base capNodes t u cnt k v : ℕ} {x : WordRAM.Data 20} (ht : 2 ≤ t) (hbdd : WordRAM.Data.Bounded w x) (hfit : WordRAM.Fits w (base + arenaWords t capNodes)) (hv : ValidNode l base t x.mem u) (hs : SortedNode l base t x.mem u) (hnonfull : numKeys base t x.mem u ≤ 2 * t - 2) (hrange : readNodeSet l base t x.mem u ⊆ Finset.range cnt) (hcap : cnt + l ≤ capNodes) (hcnt_mem : x.mem (base + 1) = cnt) (hz : x.regs rZero = 0) (ho : x.regs rOne = 1) (hbase : x.regs Reg.rBase = base) (hdeg : x.regs Reg.rDeg = t) (hstride : x.regs rStride = 6 * t) (hkey : x.regs Reg.rKey = k) (hval : x.regs Reg.rVal = v) (hcur : x.regs rCur = u) (hcnt_reg : x.regs rCnt = cnt) (hact : x.regs rActive = 1) :
∃ (y : WordRAM.Data 20) (cnt' : ℕ), WordRAM.ExecWithin w insertLoop x y ((91 * t + 160) * (l + 1) + 2) ∧ WordRAM.Data.Bounded w y ∧ cnt ≤ cnt' ∧ cnt' ≤ cnt + l ∧ y.mem base = x.mem base ∧ y.mem (base + 1) = cnt' ∧ y.regs Reg.rBase = base ∧ y.regs Reg.rDeg = t ∧ WordRAM.Modifies { base := base, length := arenaWords t capNodes }.footprint x.mem y.mem ∧ (∀ w_id ∉ readNodeSet l base t x.mem u ∪ Finset.Ico cnt cnt', ∀ o < nodeStride t, y.mem (nodeAddr base t w_id + o) = x.mem (nodeAddr base t w_id + o)) ∧ ValidNode l base t y.mem u ∧ SortedNode l base t y.mem u ∧ numKeys base t x.mem u ≤ numKeys base t y.mem u ∧ readNodeSet l base t y.mem u ⊆ readNodeSet l base t x.mem u ∪ Finset.Ico cnt cnt' ∧ (readTree l base t y.mem u).toList = SortedAssoc.insert k v (readTree l base t x.mem u).toList

Specification of insertLoop starting from non-full node u of height l: runs in at most (91 * t + 160) * (l + 1) + 2 instructions, allocating at most l nodes while preserving ValidNode/SortedNode and realizing Cslib.SortedAssoc.insert k v.