Single-Node Leaf, Value-Overwrite, and Singleton-Root Subprograms #
Internal Word-RAM subroutines used privately by InsertLoop and Insert (never re-exported
publicly by CslibFrontier.DataStructure.BTree.WordRAM):
leafInsertCode(leafInsertCode_spec): shift-inserts(k, v)into a non-full leaf nodeu(memInsertLeaf).overwriteValCode(overwriteValCode_spec): overwrites the value at slotslotof nodeuin place (memOverwriteVal).initSingleCode(initSingleCode_spec): initializes node0as a singleton leaf root(k, v)when inserting into an empty arena (memInitSingle).
Shift-insert (rKey, rVal) at rSlot in non-full leaf rCur (memInsertLeaf).
theorem Cslib.DataStructure.BTree.WordRAM.leafInsertCode_spec {w base capNodes t u m slot k v : ℕ} {x : WordRAM.Data 20} (ht : 2 ≤ t) (hu_cap : u < capNodes) (hm_le : m ≤ 2 * t - 2) (hslot : slot ≤ m) (hbdd : WordRAM.Data.Bounded w x) (hfit : WordRAM.Fits w (base + arenaWords t capNodes)) (ho : x.regs rOne = 1) (hbase : x.regs Reg.rBase = base) (hdeg : x.regs Reg.rDeg = t) (hkey : x.regs Reg.rKey = k) (hval : x.regs Reg.rVal = v) (hnk : x.regs rNumK = m) (hslot_reg : x.regs rSlot = slot) (hsrc : x.regs rSrc = nodeAddr base t u + 2) :
∃ (y : WordRAM.Data 20),
WordRAM.ExecWithin w leafInsertCode x y (36 * t + 22) ∧ WordRAM.Data.Bounded w y ∧ y.mem = memInsertLeaf base t u m slot k v x.mem ∧ WordRAM.Modifies { base := base, length := arenaWords t capNodes }.footprint x.mem y.mem ∧ y.regs Reg.rBase = base ∧ y.regs Reg.rDeg = t ∧ y.regs rZero = x.regs rZero ∧ y.regs rActive = 0
Specification of leafInsertCode, realizing memInsertLeaf base t u m slot k v in
36 * t + 22 instructions.
Overwrite value slot rSlot of node rCur with rVal and stop the descent loop.
theorem Cslib.DataStructure.BTree.WordRAM.overwriteValCode_spec {w base capNodes t u slot v : ℕ} {x : WordRAM.Data 20} (ht : 2 ≤ t) (hu_cap : u < capNodes) (hslot : slot < 2 * t - 1) (hbdd : WordRAM.Data.Bounded w x) (hfit : WordRAM.Fits w (base + arenaWords t capNodes)) (ho : x.regs rOne = 1) (hbase : x.regs Reg.rBase = base) (hdeg : x.regs Reg.rDeg = t) (hstride : x.regs rStride = 6 * t) (hcur : x.regs rCur = u) (hslot_reg : x.regs rSlot = slot) (hval : x.regs Reg.rVal = v) :
∃ (y : WordRAM.Data 20),
WordRAM.ExecWithin w overwriteValCode x y 10 ∧ WordRAM.Data.Bounded w y ∧ y.mem = memOverwriteVal base t u slot v x.mem ∧ WordRAM.Modifies { base := base, length := arenaWords t capNodes }.footprint x.mem y.mem ∧ y.regs rZero = x.regs rZero ∧ y.regs Reg.rBase = base ∧ y.regs Reg.rDeg = t ∧ y.regs rActive = 0
Specification of overwriteValCode, realizing memOverwriteVal base t u slot v in 10
instructions.
Allocate node 0 as a singleton leaf root (rKey, rVal) when cnt = 0 (memInitSingle).
theorem Cslib.DataStructure.BTree.WordRAM.initSingleCode_spec {w base capNodes t k v : ℕ} {x : WordRAM.Data 20} (ht : 2 ≤ t) (hcap : 1 ≤ capNodes) (hbdd : WordRAM.Data.Bounded w x) (hfit : WordRAM.Fits w (base + arenaWords t capNodes)) (hz : x.regs rZero = 0) (ho : x.regs rOne = 1) (hbase : x.regs Reg.rBase = base) (hdeg : x.regs Reg.rDeg = t) (hkey : x.regs Reg.rKey = k) (hval : x.regs Reg.rVal = v) :
∃ (y : WordRAM.Data 20),
WordRAM.ExecWithin w initSingleCode x y 14 ∧ WordRAM.Data.Bounded w y ∧ y.mem = memInitSingle base t k v x.mem ∧ WordRAM.Modifies { base := base, length := arenaWords t capNodes }.footprint x.mem y.mem ∧ y.regs Reg.rBase = base ∧ y.regs Reg.rDeg = t
Specification of initSingleCode, realizing memInitSingle base t k v in 14 instructions.