Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.CuckooHashing.Rehash

Word-RAM Cuckoo Hashing: Las Vegas Rehashing and Insertion #

This module implements full-table Las Vegas rehashing (rehashLoopCode) and dictionary insertion (insertCode) for Pagh and Rodler's cuckoo hashing dictionary [PR04] on the randomized Word RAM, building on the layout, lookup, and bounded displacement primitives in CslibFrontier.DataStructure.Dictionary.WordRAM.CuckooHashing.Evict.

When evictLoopCode reaches the displacement cap maxEvictions n_max during a new-key insertion, rehashLoopCode repeatedly resamples both hash blocks via resampleAtBaseCode, clears T₁ and T₂, and replays insKeys in insertion order until all stored keys settle. By loopExitPMF_map_eq_uniformOfFinset, the resulting exit seed is distributed uniformly over survivingSeeds evalHash1 evalHash2 (maxEvictions n_max) ks.

Main definitions #

Main results #

References #

Table clearing and insertion-order replay (clearTablesCode, replayLoopCode) #

Las Vegas full-table rehashing (rehashLoopCode, rehashLoopCode_execCodeDist) #

def Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.RehashLoopInv (w base c_exp n_max U V : ℕ) (ks : List (Fin U)) (s : State U) (x₀ z : WordRAM.Data 19) :

Loop invariant for rehashLoopCode: machine configuration is word-bounded, reg 0 = base, the header and HashPairTableRep are intact, insKeys / insVals realize (ks, s), and all memory modifications since x₀ lie inside [base, base + space c_exp n_max).

def Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.RehashLoopPost (w base c_exp n_max U V : ℕ) (ks : List (Fin U)) (s : State U) (x₀ z : WordRAM.Data 19) :

Exit postcondition for rehashLoopCode: RehashLoopInv holds together with HashPairRep for θ_mem = extractSeed ... z.mem and a valid replayed table tbl in T₁, T₂.

Under the ≤ 1 / 2 rehash failure probability bound hreh, every duplicate-free key list ks of length at most n_max has a nonempty set of surviving seeds of cardinality at least half the seed space.

Las Vegas rehash loop: synchronizes (Cond.lt 18 17) from mem[base + 16] and repeats rehashAttemptCode while 0 < mem[base + 16].

theorem Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.rehashLoopSteps_eq (c_exp n_max U : ℕ) :
rehashLoopSteps c_exp n_max U = 2 * (resampleAtBaseSteps c_exp n_max + (8 * CuckooHashing.tableSize n_max + 10) + (n_max * (CuckooHashing.maxEvictions n_max * evictIterSteps c_exp n_max U + 54) + 23) + 4) + 10
theorem Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.rehashLoopCode_execCodeDist {w base c_exp n_max U V : ℕ} {ks : List (Fin U)} {s : State U} {x₀ x : WordRAM.Data 19} (hreh : ∀ (S : Finset (Fin U)), S.card ≤ n_max → (seedLaw c_exp n_max U (CuckooHashing.tableBits n_max)).toOuterMeasure {θ : Seed c_exp n_max U (CuckooHashing.tableBits n_max) | ¬CuckooHashing.GoodForSet (evalHash1 θ) (evalHash2 θ) (CuckooHashing.maxEvictions n_max) S} ≤ 1 / 2) (hinv : RehashLoopInv w base c_exp n_max U V ks s x₀ x) (hm16 : x.mem (base + 16) = 1) (hfit_ev : WordRAM.Fits w (CuckooHashing.maxEvictions n_max)) (hw : 2 * Probability.trinomialDeg U (CuckooHashing.tableBits n_max) ≤ w) (hfit_end : WordRAM.Fits w (base + space c_exp n_max)) (hfit_q : WordRAM.Fits w (2 ^ Probability.trinomialDeg U (CuckooHashing.tableBits n_max))) :
∃ (μ_reh : PMF (WordRAM.Data 19)) (hE : (CuckooHashing.survivingSeeds evalHash1 evalHash2 (CuckooHashing.maxEvictions n_max) ks).Nonempty), WordRAM.ExecCodeDist w (rehashLoopCode c_exp n_max) x μ_reh ↑(rehashLoopSteps c_exp n_max U) ∧ PMF.map (fun (y : WordRAM.Data 19) => extractSeed (hashBase base) c_exp n_max U (CuckooHashing.tableBits n_max) y.mem) μ_reh = Probability.PMF.uniformOfFinset (CuckooHashing.survivingSeeds evalHash1 evalHash2 (CuckooHashing.maxEvictions n_max) ks) hE ∧ ∀ y ∈ μ_reh.support, RehashLoopPost w base c_exp n_max U V ks s x₀ y

Geometric Las Vegas termination, expected step bound, and exact conditional-uniform exit law for rehashLoopCode.

Dictionary insertion (insertCode, insertCode_execCodeDist) #

Full insert operation (insertCode): stores u.val = reg 3 in mem[base + 11] and v = reg 4 in mem[base + 18], runs probeKeyCode, and branches on foundFlag = mem[base + 13] between in-place value overwrite and new-key insertion with bounded eviction and Las Vegas rehash.

Base step overhead of insertCode outside the eviction and rehash loops.

Worst-case expected step bound of insertCode when a rehash may be triggered.

noncomputable def Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.insertSeedSteps (c_exp n_max U : ℕ) (ks : List (Fin U)) (θ : Seed c_exp n_max U (CuckooHashing.tableBits n_max)) (s : State U) (u : Fin U) :

State-and-seed-dependent step bound for insertCode on insertion-order key list ks, seed θ, dictionary state s, and key u.

theorem Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.insertSeedSteps_le_insertWorstSteps (c_exp n_max U : ℕ) (ks : List (Fin U)) (θ : Seed c_exp n_max U (CuckooHashing.tableBits n_max)) (s : State U) (u : Fin U) :
insertSeedSteps c_exp n_max U ks θ s u ≤ ↑(insertWorstSteps c_exp n_max U)

Insertion-order key list after executing dictionary operation o from key list ks.

theorem Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.insertCode_execCodeDist {w base c_exp n_max U V v : ℕ} {ks : List (Fin U)} {s : State U} {u : Fin U} {x : WordRAM.Data 19} (hreh : ∀ (S : Finset (Fin U)), S.card ≤ n_max → (seedLaw c_exp n_max U (CuckooHashing.tableBits n_max)).toOuterMeasure {θ : Seed c_exp n_max U (CuckooHashing.tableBits n_max) | ¬CuckooHashing.GoodForSet (evalHash1 θ) (evalHash2 θ) (CuckooHashing.maxEvictions n_max) S} ≤ 1 / 2) (hrep : RepWithKeys w base c_exp n_max U V ks s x) (h3 : x.regs 3 = ↑u) (h4 : x.regs 4 = v) (hpre : ((dom s).card < n_max ∨ (s u).isSome = true) ∧ v < V) (hfit_ev : WordRAM.Fits w (CuckooHashing.maxEvictions n_max)) (hw : 2 * Probability.trinomialDeg U (CuckooHashing.tableBits n_max) ≤ w) (hfit_end : WordRAM.Fits w (base + space c_exp n_max)) (hfit_q : WordRAM.Fits w (2 ^ Probability.trinomialDeg U (CuckooHashing.tableBits n_max))) :
have θ_mem := extractSeed (hashBase base) c_exp n_max U (CuckooHashing.tableBits n_max) x.mem; ∃ (μ_ins : PMF (WordRAM.Data 19)) (hE' : (CuckooHashing.survivingSeeds evalHash1 evalHash2 (CuckooHashing.maxEvictions n_max) (stepKeys ks (Op.insert u v))).Nonempty), WordRAM.ExecCodeDist w (insertCode c_exp n_max) x μ_ins (insertSeedSteps c_exp n_max U ks θ_mem s u) ∧ (PMF.map (fun (y : WordRAM.Data 19) => extractSeed (hashBase base) c_exp n_max U (CuckooHashing.tableBits n_max) y.mem) μ_ins = if θ_mem ∈ CuckooHashing.survivingSeeds evalHash1 evalHash2 (CuckooHashing.maxEvictions n_max) (stepKeys ks (Op.insert u v)) then PMF.pure θ_mem else Probability.PMF.uniformOfFinset (CuckooHashing.survivingSeeds evalHash1 evalHash2 (CuckooHashing.maxEvictions n_max) (stepKeys ks (Op.insert u v))) hE') ∧ ∀ y ∈ μ_ins.support, y.regs 2 = 0 ∧ RepWithKeys w base c_exp n_max U V (stepKeys ks (Op.insert u v)) (Function.update s u (some v)) y ∧ WordRAM.Modifies { base := base, length := space c_exp n_max }.footprint x.mem y.mem

Distributional execution specification for insertCode maintaining RepWithKeys and exact conditional-uniform surviving-seed transition.