Documentation

CslibFrontier.DataStructure.BTree.WordRAM.Rep

Word-RAM B-Tree Interface Registers, Rep Invariant, and Arena Initialization #

Caller-visible register bank (Reg.rBase..rFound), Word-RAM representation invariant Rep coupling a 20-register machine state x : Data 20 to a well-formed BTree ℕ ℕ in [base, base + arenaWords t capNodes), allocated-node counter allocCount, and O(1) empty-arena initializer initCode (initCode_spec).

Main definitions #

Main results #

Persistent base address of the B-tree arena [base, base + arenaWords t capNodes).

Persistent minimum degree t (2 ≤ t).

Search or insertion key k.

Insertion value v (input to insertCode) / lookup value (output of lookupCode).

Lookup hit flag (1 when k is present, 0 when absent).

structure Cslib.DataStructure.BTree.WordRAM.Rep (base capNodes t w : ℕ) (tr : BTree ℕ ℕ) (x : WordRAM.Data 20) :

Word-RAM representation of a classic minimum-degree-t BTree ℕ ℕ in the memory block [base, base + arenaWords t capNodes) at word width w.

Number of arena nodes currently allocated in x (x.mem (base + 1)).

@[simp]
theorem Cslib.DataStructure.BTree.WordRAM.allocCount_set (base : ℕ) (x : WordRAM.Data 20) (r : Fin 20) (v : ℕ) :
allocCount base (x.set r v) = allocCount base x
theorem Cslib.DataStructure.BTree.WordRAM.Rep.allocCount_le_cap {base capNodes t w : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) :
allocCount base x ≤ capNodes

Allocated node count never exceeds capNodes under Rep.

theorem Cslib.DataStructure.BTree.WordRAM.Rep.set_of_ne {base capNodes t w : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) {r : Fin 20} (hb : r ≠ Reg.rBase) (hd : r ≠ Reg.rDeg) {v : ℕ} (hv : WordRAM.Fits w v) :
Rep base capNodes t w tr (x.set r v)

Setting any register other than rBase and rDeg to a w-bit word preserves Rep.

theorem Cslib.DataStructure.BTree.WordRAM.Rep.setKey {base capNodes t w : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) {k : ℕ} (hk : WordRAM.Fits w k) :
Rep base capNodes t w tr (x.set Reg.rKey k)

Setting rKey to a w-bit word preserves Rep.

theorem Cslib.DataStructure.BTree.WordRAM.Rep.setKeyVal {base capNodes t w : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) {k v : ℕ} (hk : WordRAM.Fits w k) (hv : WordRAM.Fits w v) :
Rep base capNodes t w tr ((x.set Reg.rKey k).set Reg.rVal v)

Setting rKey and rVal to w-bit words preserves Rep.

theorem Cslib.DataStructure.BTree.WordRAM.Rep.isWF {base capNodes t w : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) :
IsWF t tr

Every represented B-tree satisfies BTree.IsWF t tr.

theorem Cslib.DataStructure.BTree.WordRAM.Rep.isSortedAssoc {base capNodes t w : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) :

Every represented B-tree has sorted key-value inorder traversal tr.toList.

theorem Cslib.DataStructure.BTree.WordRAM.Rep.height_le_log {base capNodes t w : ℕ} {tr : BTree ℕ ℕ} {x : WordRAM.Data 20} (hr : Rep base capNodes t w tr x) :
tr.height ≤ Nat.log t ((tr.size + 1) / 2) + 1

Every represented B-tree has height at most Nat.log t ((tr.size + 1) / 2) + 1.

Initialize [base, base + 2) to (root = 0, cnt = 0).

theorem Cslib.DataStructure.BTree.WordRAM.initCode_spec {w base capNodes t : ℕ} {x : WordRAM.Data 20} (ht : 2 ≤ t) (hbdd : WordRAM.Data.Bounded w x) (hbase : x.regs Reg.rBase = base) (hdeg : x.regs Reg.rDeg = t) (hfit : WordRAM.Fits w (base + arenaWords t capNodes)) :
∃ (y : WordRAM.Data 20), WordRAM.ExecWithin w initCode x y 5 ∧ Rep base capNodes t w leaf y ∧ allocCount base y = 0 ∧ WordRAM.Modifies { base := base, length := arenaWords t capNodes }.footprint x.mem y.mem

initCode initializes an empty B-tree .leaf (allocCount base y = 0) in at most 5 standard Word-RAM instructions, modifying only [base, base + arenaWords t capNodes).