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 #
Cslib.DataStructure.BTree.WordRAM.Reg.rBase,Cslib.DataStructure.BTree.WordRAM.Reg.rDeg,Cslib.DataStructure.BTree.WordRAM.Reg.rKey,Cslib.DataStructure.BTree.WordRAM.Reg.rVal,Cslib.DataStructure.BTree.WordRAM.Reg.rFound: caller-visible Word-RAM interface registers.Cslib.DataStructure.BTree.WordRAM.RepandCslib.DataStructure.BTree.WordRAM.allocCount: coupling invariant and allocated-node count (x.mem (base + 1)).Cslib.DataStructure.BTree.WordRAM.initCode:O(1)empty-arena initializer overBasis.standard.
Main results #
Cslib.DataStructure.BTree.WordRAM.Rep.isWF,Cslib.DataStructure.BTree.WordRAM.Rep.isSortedAssoc,Cslib.DataStructure.BTree.WordRAM.Rep.height_le_log: well-formedness, sortedness, and logarithmic height bound fromRep.Cslib.DataStructure.BTree.WordRAM.Rep.allocCount_le_cap,Cslib.DataStructure.BTree.WordRAM.Rep.set_of_ne,Cslib.DataStructure.BTree.WordRAM.Rep.setKey,Cslib.DataStructure.BTree.WordRAM.Rep.setKeyVal: node-count bound and register framing forRep.Cslib.DataStructure.BTree.WordRAM.initCode_spec:O(1)Word-RAM initialization of.leaf.
Persistent base address of the B-tree arena [base, base + arenaWords t capNodes).
Insertion value v (input to insertCode) / lookup value (output of lookupCode).
Lookup hit flag (1 when k is present, 0 when absent).
Word-RAM representation of a classic minimum-degree-t BTree ℕ ℕ in the memory block
[base, base + arenaWords t capNodes) at word width w.
- bounded : WordRAM.Data.Bounded w x
All registers and memory cells fit in
w-bit words. - two_le : 2 ≤ t
Minimum degree is at least
2. rBaseholdsbase.rDegholdst.Every address up to
base + arenaWords t capNodesfits in aw-bit word.Allocated node count
x.mem (base + 1)does not exceedcapNodes.- tree_spec : x.mem (base + 1) = 0 ∧ tr = leaf ∨ 0 < x.mem (base + 1) ∧ ∃ (l : ℕ), tr = readTree l base t x.mem (x.mem base) ∧ ValidNode l base t x.mem (x.mem base) ∧ SortedNode l base t x.mem (x.mem base) ∧ readNodeSet l base t x.mem (x.mem base) ⊆ Finset.range (x.mem (base + 1))
Either
cnt = 0(tr = .leaf), or0 < cntandx.mem baseroots a valid, sorted B-tree whose node indices lie inFinset.range (x.mem (base + 1)).
Number of arena nodes currently allocated in x (x.mem (base + 1)).
Allocated node count never exceeds capNodes under Rep.
Setting any register other than rBase and rDeg to a w-bit word preserves Rep.
Every represented B-tree satisfies BTree.IsWF t tr.
Every represented B-tree has sorted key-value inorder traversal tr.toList.
Initialize [base, base + 2) to (root = 0, cnt = 0).
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).