Depth-d binary trie operations in flat word memory #
Allocation (trieInit), O(d + 1) lookup (trieGet), and O(d + 1) lazy-allocating point update
(trieSet) for depth-d binary tries stored in flat Word-RAM memory without assuming pre-zeroed
scratch space.
Main definitions #
Cslib.Algorithms.WordRAM.TrimmedYates.trieInit,trieGet,trieSet: fresh root allocation, bit-indexed lookup, and lazy-allocating point update on depth-dbinary tries.
Main results #
Cslib.Algorithms.WordRAM.TrimmedYates.exec_trieInit,exec_trieGet,exec_trieSet:ExecWithinspecifications with explicit bump-pointer footprints and register/memory frames.
Allocate a fresh 2-word zeroed trie root at Reg.free.
theorem Cslib.Algorithms.WordRAM.TrimmedYates.exec_trieInit {w d free : ℕ} (x : WordRAM.Data numRegs) (hz : x.regs rZero = 0) (ho : x.regs rOne = 1) (hf : x.regs Reg.free = free) (hpos : 0 < free) (hfit : WordRAM.Fits w (free + 2)) :
∃ (y : WordRAM.Data numRegs),
WordRAM.ExecWithin w trieInit x y 5 ∧ y.regs rTrieRoot = free ∧ y.regs Reg.free = free + 2 ∧ (TrieRep y.mem d free {free, free + 1} fun (x : ℕ) => 0) ∧ (∀ (a : ℕ), a ≠ free ∧ a ≠ free + 1 → y.mem a = x.mem a) ∧ ∀ (i : Fin numRegs), i ≠ rTrieRoot ∧ i ≠ Reg.free → y.regs i = x.regs i
Lookup rTrieKey in depth-Reg.dim trie rTrieRoot, placing result in rTrieVal.
theorem Cslib.Algorithms.WordRAM.TrimmedYates.exec_trieGet {w bound d root key : ℕ} {fn : ℕ → ℕ} (x : WordRAM.Data numRegs) (hz : x.regs rZero = 0) (ho : x.regs rOne = 1) (hd : x.regs Reg.dim = d) (hr : x.regs rTrieRoot = root) (hk : x.regs rTrieKey = key) (htrie : HoldsTrie x.mem bound d root fn) (hfit_bound : WordRAM.Fits w bound) (hfit_d : WordRAM.Fits w d) (hfit_key : WordRAM.Fits w key) :
Set rTrieKey to rTrieVal in depth-Reg.dim trie rTrieRoot (0 < rTrieRoot).
theorem Cslib.Algorithms.WordRAM.TrimmedYates.exec_trieSet {w lo d root key val free : ℕ} {S : Set ℕ} {fn : ℕ → ℕ} (x : WordRAM.Data numRegs) (hz : x.regs rZero = 0) (ho : x.regs rOne = 1) (hd : x.regs Reg.dim = d) (hr : x.regs rTrieRoot = root) (hk : x.regs rTrieKey = key) (hv : x.regs rTrieVal = val) (hfree : x.regs Reg.free = free) (hlo : 1 ≤ lo) (hfree_lo : lo ≤ free) (hroot : 0 < root) (hS : S ⊆ Set.Ico lo free) (hrep : TrieRep x.mem d root S fn) (hkey_lt : key < 2 ^ d) (hfit_free : WordRAM.Fits w (free + 2 * d)) (hfit_d : WordRAM.Fits w d) (hfit_key : WordRAM.Fits w key) :
∃ (y : WordRAM.Data numRegs) (S' : Set ℕ) (free' : ℕ),
WordRAM.ExecWithin w trieSet x y (14 * d + 6) ∧ y.regs Reg.free = free' ∧ free ≤ free' ∧ free' ≤ free + 2 * d ∧ S' ⊆ Set.Ico lo free' ∧ (∀ (a : ℕ), a < lo ∨ free' ≤ a → y.mem a = x.mem a) ∧ (TrieRep y.mem d root S' fun (m : ℕ) => if m % 2 ^ d = key then val else fn m) ∧ ∀ (i : Fin numRegs), i ≠ Reg.free ∧ (↑i < 19 ∨ 23 ≤ ↑i) → y.regs i = x.regs i