Documentation

CslibFrontier.DataStructure.BTree.WordRAM.Insert

Word-RAM B-Tree Proactive Top-Down Insertion (O(t log_t n)) #

Proactive top-down B-tree insertion code insertCode and halting flat program insertProgram over Cslib.WordRAM.Basis.standard (20 registers), following [CLRS09], Section 18.2: splits a full root via splitRootCode and descends through non-full nodes via insertLoop, realizing Cslib.SortedAssoc.insert k v tr.toList in O(t log_t n) Word-RAM instructions while preserving Rep (BTree.IsWF t) and outside memory.

Main definitions #

Main results #

References #

Insert (rKey, rVal) into the B-tree arena at rBase of minimum degree rDeg using proactive top-down node splitting ([CLRS09], Section 18.2).

theorem Cslib.DataStructure.BTree.WordRAM.insertCode_spec {w base capNodes t k v : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) (hkey : x.regs Reg.rKey = k) (hval : x.regs Reg.rVal = v) (hcap : allocCount base x + tr.height + 2 ≤ capNodes) :
∃ (y : WordRAM.Data 20) (tr' : BTree ℕ ℕ), WordRAM.ExecWithin w insertCode x y ((91 * t + 160) * (tr.height + 1) + (21 * t + 120)) ∧ Rep base capNodes t w tr' y ∧ tr'.toList = SortedAssoc.insert k v tr.toList ∧ allocCount base y ≤ allocCount base x + tr.height + 2 ∧ WordRAM.Modifies { base := base, length := arenaWords t capNodes }.footprint x.mem y.mem

insertCode inserts (k, v) into tr in at most (91 * t + 160) * (tr.height + 1) + (21 * t + 120) standard Word-RAM instructions, preserving Rep (BTree.IsWF t tr'), realizing Cslib.SortedAssoc.insert k v tr.toList, allocating at most tr.height + 2 arena nodes, and modifying only [base, base + arenaWords t capNodes).

theorem Cslib.DataStructure.BTree.WordRAM.insertCode_log_spec {w base capNodes t k v : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) (hkey : x.regs Reg.rKey = k) (hval : x.regs Reg.rVal = v) (hcap : allocCount base x + tr.height + 2 ≤ capNodes) :
∃ (y : WordRAM.Data 20) (tr' : BTree ℕ ℕ), WordRAM.ExecWithin w insertCode x y ((91 * t + 160) * (Nat.log t ((tr.size + 1) / 2) + 2) + (21 * t + 120)) ∧ Rep base capNodes t w tr' y ∧ tr'.toList = SortedAssoc.insert k v tr.toList ∧ allocCount base y ≤ allocCount base x + tr.height + 2 ∧ WordRAM.Modifies { base := base, length := arenaWords t capNodes }.footprint x.mem y.mem

Logarithmic O(t log_t n) Word-RAM instruction bound for insertCode.

Complete flat Word-RAM insertion program (insertCode followed by halt rBase).

theorem Cslib.DataStructure.BTree.WordRAM.insertProgram_spec {w base capNodes t k v : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) (hkey : x.regs Reg.rKey = k) (hval : x.regs Reg.rVal = v) (hcap : allocCount base x + tr.height + 2 ≤ capNodes) :
∃ (y : WordRAM.Data 20) (tr' : BTree ℕ ℕ) (steps : ℕ), WordRAM.Runs w insertProgram { pc := 0, data := x } { pc := insertCode.size, data := y } steps ∧ WordRAM.step w insertProgram { pc := insertCode.size, data := y } = WordRAM.Outcome.halt base ∧ steps + 1 ≤ (91 * t + 160) * (Nat.log t ((tr.size + 1) / 2) + 2) + (21 * t + 121) ∧ Rep base capNodes t w tr' y ∧ tr'.toList = SortedAssoc.insert k v tr.toList ∧ allocCount base y ≤ allocCount base x + tr.height + 2 ∧ WordRAM.Modifies { base := base, length := arenaWords t capNodes }.footprint x.mem y.mem

Complete halting flat-program specification of insertProgram: runs in at most (91 * t + 160) * (Nat.log t ((tr.size + 1) / 2) + 2) + (21 * t + 121) Word-RAM instructions (charging the final halt), halting with base in rBase while preserving Rep on tr' with tr'.toList = Cslib.SortedAssoc.insert k v tr.toList, bounding node allocation, and modifying only [base, base + arenaWords t capNodes).