Pagh–Rodler Cuckoo Graph Dichotomy and Walk Tail Bounds for Highly Independent Hash Pairs #
This module formalizes the cuckoo graph walk dichotomy and tail-bound analysis of Rasmus Pagh and
Flemming Friche Rodler, "Cuckoo hashing" (author-hosted journal manuscript dated 8 December 2003,
https://www.rasmuspagh.net/papers/cuckoo-jour.pdf, published in Journal of Algorithms
51(2):122–144, 2004) [PR04], Section 2.3 ("Analysis", manuscript pp. 6–10; Lemma 1 on
manuscript p. 7, Eqs. (1)–(3) on manuscript p. 9, and the rehash analysis on manuscript p. 10). For
every capacity n_max : ℕ, it proves that any independent pair of (2 * MaxLoop + 2)-wise
independent hash functions into sub-tables of size 32 * max n_max 4 ≤ m with eviction cap
maxEvictions n_max ≤ MaxLoop ≤ m satisfies IsCuckooHashPair with constants C_walk = 2 and
C_reh = 3.
Scope and Word-RAM specialization #
This module establishes IsCuckooHashPair for uniform random hash pairs
(isCuckooHashPair_uniform, connected to lazy random-oracle evaluation via
uniform_interpret_eq_lazy_hashPair), for explicit (2 * MaxLoop + 2)-wise independent
polynomial hash pairs (isCuckooHashPair_trinomialPolyHash), for Mikkel Thorup's double-tabulation
hash family (isCuckooHashPair_doubleTabHash). It imports no Word-RAM modules. The concrete
regime-switched hash pair is connected to this analysis by
CslibFrontier.DataStructure.Dictionary.WordRAM.CuckooHashing.Analysis, whose
isCuckooHashPair_provableFamily discharges IsCuckooHashFamily (C_walk = 3, C_reh = 4)
for every n_max : ℕ whenever U ≤ max n_max 4 ^ c_exp and 32 * max n_max 4 ≤ 2 ^ M.
Source statements, assumptions, and notation mapping #
In Pagh and Rodler [PR04] (8 December 2003 manuscript, https://www.rasmuspagh.net/papers/cuckoo-jour.pdf):
- Table size and eviction limit (Section 2, manuscript pp. 3–4; Section 2.3, manuscript p. 10):
Two hash tables
T₁, T₂each consist ofrwords holding a setSofn = |S|keys (p. 3), "assumingr ≥ (1 + ε) nfor some constantε > 0" (pp. 3–4), withMaxLoop = ⌈3 log_{1+ε} r⌉(p. 10). The Lean theorems below assume the stronger linear-space condition32 * max n_max 4 ≤ m(S.card ≤ n_max) and eviction capmaxEvictions n_max = 6 * (Nat.clog 2 (max n_max 2) + 2) ≤ MaxLoop ≤ m. - Hash-function assumption (Section 1.1, Definition 1, manuscript p. 3; Section 2.1, manuscript
p. 5; Section 2.3, manuscript p. 7): Definition 1 (p. 3) defines a family
{h_i}_{i ∈ I},h_i : U → R, as(c, k)-universal if "for anykdistinct elementsx₁, …, x_k ∈ U, anyy₁, …, y_k ∈ R, and uniformly randomi ∈ I,Pr[h_i(x₁) = y₁, …, h_i(x_k) = y_k] ≤ c / |R|^k". Section 2.1 (p. 5) invokes Siegel's construction for "a hash function family that, when restricted to any set ofr²keys, is(1, n^δ)-universal, for some constantδ > 0, with probability1 - O(1/n²)", so forMaxLoop < n^δ"with high probability the family will be(1, MaxLoop)-universal. This means thath₁andh₂will act like truly random functions on any set of keys processed during the insertion loop" (and Section 2.3, situation (1) on manuscript p. 7 separately bounds the event that "The hash function family used is not(1, MaxLoop)-universal when restricted to the set of keys in the dictionary (including the key being inserted)" byO(1/n²)). The Lean theorems below assume the stronger hypothesis thath₁andh₂are independent families each satisfyingIsKWiseIndependentHash (2 * MaxLoop + 2)on the full universeFin U → Fin m(exact(1, 2 * MaxLoop + 2)-universality with zero failure probability). - Lemma 1 (Section 2.3, manuscript p. 7): "Suppose that the insertion procedure does not enter
a closed loop. Then for any prefix
x₁, x₂, …, x_pof the sequence of nestless keys, there must be a subsequence of at leastp / 3consecutive keys without repetitions, starting with an occurrence of the keyx₁, i.e., the key being inserted." In Lean,cuckooWalk_dichotomy_bicyclicandcuckooWalk_dichotomyprove that any non-terminatingr-round (p = 2 * rhalf-step) eviction walk fromu ∉ Sproduces either a simple alternating path of lengthℓ = (2 * r + 2) / 3starting atu(HasAltPath, Case B) or a bicyclic prefix ofL + 1distinct keys (2 ≤ L < 2 * r) satisfyingL + 2hash-collision equations (HasBicyclicPrefixandHasExcessSubset, Case A). - Closed-loop and path tail bounds, expected rounds, and rehash bounds (Section 2.3, manuscript
pp. 7–10; Eqs. (1)–(3) on p. 9): For closed loops (situation (2), introduced on p. 7 and
bounded on p. 9 following Sanders and Vöcking), the manuscript counts configurations of
v ≤ ldistinct nestless keys byv³ r^{v-1} n^{v-1}("v²possible values foriandj,vpossible positions forx_l,r^{v-1}possible choices of cells, andn^{v-1}possible choices of keys other thanx₁"), each occurring with probability at mostr^{-2v}, summing toO(1 / n²)(p. 9). For simple alternating paths (situation (3), introduced on pp. 7–8 and bounded in Eqs. (1)–(2) on p. 9), a sequence ofv = ⌈(2t - 1) / 3⌉distinct keys (ℓ = v - 1steps) occurs with probability at most2 * (n / r)^{v - 1}(p. 9). Summing over rounds gives expected walk lengthO(1)(Eq. (3), p. 9;expected_walk_lewithC_walk = 2) and bounds the per-insertion and full-set rehash probabilities (p. 10;step_rehash_prob_lewithC_reh = 3andrehash_prob_le_half). - Original adaptations:
GoodForSet(requiringpureReplayto succeed for all duplicate-free insertion ordersks ⊆ Ssimultaneously) andcuckooWalkRounds(taking the supremum ofevictRoundsover allValidPlacement h₁ h₂ S tbland slot indices) are strengthened definitions fromCslibFrontier/DataStructure/Dictionary/CuckooHashing/Basic.lean; because neitherHasBicyclicPrefix/HasExcessSubsetnorHasAltPathdepends ontblor the insertion orderks, the walk dichotomy bounds both uniformly over all valid placements and insertion orders.- In place of enumerating
r^{v-1}cell tuples as inv³ r^{v-1} n^{v-1}on p. 9, both Case A (HasBicyclicPrefix) and Case B (HasAltPath) are bounded via an original elementary fresh-key equation-chain seed-counting argument (ValidEqChain), which counts index triples(p, s, j)(≤ (L + 1)³forv = L + 1) and key tuples (≤ S.card^L) and uses(2 * MaxLoop + 2)-wise independence directly onL + 2fresh-key collision equations (probabilitym^{-(L+2)}). The set-level excess-≥ 1subgraph predicateHasExcessSubsetand reductionhasBicyclicPrefix_imp_hasExcessSubsetare likewise original adaptations.
Main definitions #
Cslib.DataStructure.Dictionary.CuckooHashing.HasAltPath: Case B of the walk dichotomy — existence of a simple alternating path of lengthℓstarting atuwith subsequent keys inS.Cslib.DataStructure.Dictionary.CuckooHashing.HasBicyclicPrefix: Case A of the walk dichotomy — existence of a walk prefix ofL + 1distinct keys (uandLkeys inS) closing two cycles acrossL + 2independent hash-collision equations.Cslib.DataStructure.Dictionary.CuckooHashing.HasExcessSubset: set-level Case A predicate — existence of a subsetK ⊆ insert u Scontaininguwith3 ≤ K.card ≤ maxCardand|(K.image h₁)| + |(K.image h₂)| + 1 ≤ K.card.
Main results #
Cslib.DataStructure.Dictionary.CuckooHashing.hasAltPath_iff,Cslib.DataStructure.Dictionary.CuckooHashing.hasBicyclicPrefix_iff: plain characterizations ofHasAltPathandHasBicyclicPrefixdirectly in terms of injective key sequences and alternating / cycle-closing hash collisions, without internal equation-chain helpers.Cslib.DataStructure.Dictionary.CuckooHashing.hasBicyclicPrefix_imp_hasExcessSubset: any bicyclic prefix of lengthL ∈ [2, 2 * r)yields an excess-≥ 1subsetK ⊆ insert u Sof size3 ≤ K.card ≤ 2 * r.Cslib.DataStructure.Dictionary.CuckooHashing.cuckooWalk_dichotomy_bicyclic,Cslib.DataStructure.Dictionary.CuckooHashing.cuckooWalk_dichotomy,Cslib.DataStructure.Dictionary.CuckooHashing.lt_cuckooWalkRounds_imp_dichotomy: Pagh and Rodler [PR04], Section 2.3, Lemma 1 (manuscript p. 7) — any non-terminatingr-round cuckoo walk fromu ∉ Sproduces eitherHasAltPathof length(2 * r + 2) / 3orHasBicyclicPrefixof length2 ≤ L < 2 * r(andHasExcessSubsetof size≤ 2 * r).Cslib.DataStructure.Dictionary.CuckooHashing.isCuckooHashPair_of_kWiseIndependent: Pagh and Rodler [PR04], Section 2.3 (Lemma 1, manuscript p. 7; Eq. (3), manuscript p. 9; rehash analysis, manuscript p. 10) — any independent pair of(2 * MaxLoop + 2)-wise independent hash families satisfiesIsCuckooHashPair(C_walk = 2,C_reh = 3) under32 * max n_max 4 ≤ mandmaxEvictions n_max ≤ MaxLoop ≤ m.Cslib.DataStructure.Dictionary.CuckooHashing.isCuckooHashPair_of_whp_kWiseIndependent: black-box conditioning bridge showing that any two-level hash family whose top-level seed yields a(2 * MaxLoop + 2)-wise independent bottom-level family with failure probability at most1 / (2 * max n_max 1 * max MaxLoop 1)satisfiesIsCuckooHashPair(C_walk = 3,C_reh = 4).Cslib.DataStructure.Dictionary.CuckooHashing.isCuckooHashPair_doubleTabHash:IsCuckooHashPairfor Mikkel Thorup's double-tabulation hash family [Tho13], under the displayed independence, table-size, eviction-cap, and code-count bounds.Cslib.DataStructure.Dictionary.CuckooHashing.isCuckooHashPair_trinomialPolyHash,Cslib.DataStructure.Dictionary.CuckooHashing.isCuckooHashPair_uniform,Cslib.DataStructure.Dictionary.CuckooHashing.uniform_interpret_eq_lazy_hashPair: specializations to explicit trinomial-field polynomial hashing and uniform random hash pairs, plus lazy random-oracle equivalence viaCslib.RandomOracle.uniform_interpret_eq_lazy.
References #
- R. Pagh and F. F. Rodler, "Cuckoo hashing" (8 December 2003 author manuscript, https://www.rasmuspagh.net/papers/cuckoo-jour.pdf, Section 2.3, "Analysis", pp. 6–10: Lemma 1, p. 7; Eqs. (1)–(3), p. 9; rehash analysis, p. 10).
- M. Thorup, Simple Tabulation, Fast Expanders, Double Tabulation, and High Independence
- M. Mitzenmacher and E. Upfal, Probability and Computing, 2nd ed.
- M. N. Wegman and J. L. Carter, New hash functions and their use in authentication and set equality
Section 1: Fresh-key equation chains and k-wise independent counting #
Section 1B: Index-level equation chains for alternating paths and bicyclic prefixes #
Plain characterization of HasAltPath without internal equation-chain helpers: HasAltPath
holds iff there exist an initial table polarity b : Bool and an injective sequence
y : Fin (ℓ + 1) → Fin U starting at y 0 = u with y i.succ ∈ S whose consecutive keys collide
alternately under h₁ (false) and h₂ (true).
Case A (HasBicyclicPrefix): there exists a walk prefix of L + 1 pairwise distinct keys
starting at u (y 0 = u, y 1, ..., y L ∈ S) that closes two distinct cycles, forming an
independent system of L + 2 hash-collision equations across (h₁, h₂).
Instances For
Plain characterization of HasBicyclicPrefix without internal equation-chain helpers:
HasBicyclicPrefix h₁ h₂ S u L holds iff there exist cycle indices p, s, j : Fin (L + 1) and an
injective sequence y : Fin (L + 1) → Fin U (y 0 = u, y i.succ ∈ S) satisfying the two
cycle-closing collision equations together with the L fresh-step collision equations.
Set-level excess-≥ 1 subgraph (HasExcessSubset): there exists a subset
K ⊆ insert u S containing u of size 3 ≤ K.card ≤ maxCard whose images under h₁ and h₂
have combined size at most K.card - 1.
Instances For
Section 2: Half-step trace of pureEvict and Pagh–Rodler Lemma 1 (cuckooWalk_dichotomy) #
Any bicyclic walk prefix of parameter L ∈ [2, 2 * r) yields a subset K ⊆ insert u S
containing u with 3 ≤ K.card ≤ 2 * r and (K.image h₁).card + (K.image h₂).card + 1 ≤ K.card.
Pagh & Rodler (2004), Section 2.3, Lemma 1 (bicyclic form):
If pureEvict h₁ h₂ r tbl₀ e₀ = none (1 ≤ r) from a valid placement tbl₀ of S with
e₀.key = u ∉ S, then either HasAltPath h₁ h₂ S u ((2 * r + 2) / 3) holds or there is some
L ∈ Finset.Ico 2 (2 * r) with HasBicyclicPrefix h₁ h₂ S u L.
Pagh & Rodler (2004), Section 2.3, Lemma 1 (excess-subset form):
If pureEvict h₁ h₂ r tbl₀ e₀ = none (1 ≤ r) from a valid placement tbl₀ of S with
e₀.key = u ∉ S, then either HasAltPath h₁ h₂ S u ((2 * r + 2) / 3) (Case B) or
HasExcessSubset h₁ h₂ S u (2 * r) (Case A) holds.
If 1 ≤ r and r < cuckooWalkRounds h₁ h₂ maxLoop S u with u ∉ S, then either
HasAltPath h₁ h₂ S u ((2 * r + 2) / 3) holds or there is L ∈ Finset.Ico 2 (2 * r) with
HasBicyclicPrefix h₁ h₂ S u L.
Section 3: Seed-count tail bounds and rehash union bounds #
Section 4: IsCuckooHashPair instances and lazy random-oracle equivalence #
Pagh & Rodler (2004), Section 2.3 (IsCuckooHashPair for (2 * MaxLoop + 2)-wise
independent hash pairs):
For any capacity n_max : ℕ, sub-table size m with 32 * max n_max 4 ≤ m, eviction cap
MaxLoop with maxEvictions n_max ≤ MaxLoop ≤ m, and independent hash families
h₁ : Θ₁ → Fin U → Fin m and h₂ : Θ₂ → Fin U → Fin m each satisfying
IsKWiseIndependentHash (2 * MaxLoop + 2), the uniform product distribution on Θ₁ × Θ₂ satisfies
IsCuckooHashPair with universal constants C_walk = 2 and C_reh = 3.
IsCuckooHashPair for two independent trinomialPolyHash polynomials:
When U ≤ 2 ^ (2 * 3 ^ t), M ≤ 2 * 3 ^ t, 32 * max n_max 4 ≤ 2 ^ M, and
maxEvictions n_max ≤ MaxLoop ≤ 2 ^ M, two independent degree-< k (2 * MaxLoop + 2 ≤ k)
trinomial-field polynomial hashes trinomialPolyHash t k U M satisfy IsCuckooHashPair with
C_walk = 2 and C_reh = 3.
IsCuckooHashPair for a uniform random hash pair:
When 32 * max n_max 4 ≤ m and maxEvictions n_max ≤ MaxLoop ≤ m, sampling (h₁, h₂) uniformly
at random from (Fin U → Fin m) × (Fin U → Fin m) satisfies IsCuckooHashPair with C_walk = 2
and C_reh = 3.
Lazy random-oracle equivalence for the uniform cuckoo hash pair:
Sampling (h₁, h₂) eagerly from PMF.uniformOfFintype ((Fin U → Fin m) × (Fin U → Fin m)) and
interpreting queries (b, x) : Bool × Fin U via if b then h₂ x else h₁ x has the exact same
output distribution as answering each distinct query (b, x) lazily on demand with an independent
uniform bucket in Fin m via RandomOracle.answer.
Section 5: High-probability k-wise independence bridge and Double Tabulation #
Black-box high-probability k-wise independence conditioning bridge into
IsCuckooHashPair:
Given a two-level hash family H : Θ_top → Θ_bot → Fin U → Fin m and a good top-seed set
GoodTop : Finset Θ_top such that:
H αis(2 * MaxLoop + 2)-wise independent for everyα ∈ GoodTop, and2 * (|Θ_top| - |GoodTop|) * (max n_max 1 * max MaxLoop 1) ≤ |Θ_top|, under32 * max n_max 4 ≤ mandmaxEvictions n_max ≤ MaxLoop ≤ m, two independent draws fromΘ_top × Θ_botsatisfyIsCuckooHashPairwith constantsC_walk = 3andC_reh = 4.
IsCuckooHashPair for Mikkel Thorup's Double Tabulation ([Thorup2013], Theorem 1(a),
p. 4):
When 1 ≤ c, U ≤ 2 ^ (c * b), 32 * max n_max 4 ≤ 2 ^ M,
maxEvictions n_max ≤ MaxLoop ≤ 2 ^ M, and
2 * (max n_max 1 * max MaxLoop 1) * doubleTabCodeBound c (8 * c) 4 (2 * MaxLoop + 2) ≤
2 ^ (3 * b),
two independent draws from DoubleTabTopSeed c (8 * c) b × DoubleTabBotSeed (8 * c) b M satisfy
IsCuckooHashPair with constants C_walk = 3 and C_reh = 4.