Documentation

CslibFrontier.DataStructure.Dictionary.CuckooHashing.HashFamily

Probabilistic cuckoo hash-pair contract #

IsCuckooHashPair packages the expected displacement, whole-set rehash, and incremental replay failure bounds required by a cuckoo dictionary. The seed distribution and both hash functions are arbitrary; no machine representation or concrete hash-family construction is assumed.

The contract is an original strengthened sufficient interface inspired by Pagh and Rodler [PR04], Section 2.3 (8 December 2003 manuscript, pp. 6–10). Its walk count takes the supremum over all valid placements, and its goodness event requires successful replay in every insertion order. CslibFrontier.DataStructure.Dictionary.CuckooHashing proves the contract from sufficient independence assumptions. The Word-RAM specialization is in CslibFrontier.DataStructure.Dictionary.WordRAM.CuckooHashing.Analysis.

Main definitions #

Main results #

References #

structure Cslib.DataStructure.Dictionary.CuckooHashing.IsCuckooHashPair {Θ : Type u_1} (μ : PMF Θ) {U m : ℕ} (h₁ h₂ : Θ → Fin U → Fin m) (n_max MaxLoop C_walk C_reh : ℕ) :

General cuckoo hash pair interface (IsCuckooHashPair): an original strengthened sufficient assumption bundle inspired by Pagh and Rodler [PR04] (8 December 2003 manuscript, Section 2.3 "Analysis", pp. 6–10), asserting over a seed distribution μ : PMF Θ and hash pair h₁ h₂ : Θ → Fin U → Fin m:

  1. (expected_walk_le): for any set S of fewer than n_max keys and absent key u ∉ S, the expected number of worst-case displacement rounds cuckooWalkRounds (sSup over all ValidPlacements of S) is at most C_walk (cf. [PR04], §2.3, Lemma 1 on manuscript p. 7 and Eq. (3) on manuscript p. 9);
  2. (rehash_prob_le_half): for any set S of at most n_max keys, the probability that θ ∼ μ fails GoodForSet (all Nodup sublists in S) is at most 1 / 2 (so each rehash attempt succeeds with probability at least 1 / 2 and the surviving seed set has measure at least 1 / 2); and
  3. (step_rehash_prob_le): for any insertion-order prefix ks of fewer than n_max distinct keys and new key u ∉ ks, the one-step incremental failure probability that θ ∼ μ survives pureReplay (h₁ θ) (h₂ θ) MaxLoop ks yet fails pureReplay (h₁ θ) (h₂ θ) MaxLoop (ks ++ [u]) is at most C_reh / (max n_max 1 * max MaxLoop 1) (cf. [PR04], §2.3, manuscript pp. 9–10).
  • expected_walk_le (S : Finset (Fin U)) (u : Fin U) : S.card < n_max → u ∉ S → ∑' (θ : Θ), μ θ * ↑(cuckooWalkRounds (h₁ θ) (h₂ θ) MaxLoop S u) ≤ ↑C_walk

    Expected displacement rounds per new-key insertion is at most C_walk.

  • rehash_prob_le_half (S : Finset (Fin U)) : S.card ≤ n_max → μ.toOuterMeasure {θ : Θ | ¬GoodForSet (h₁ θ) (h₂ θ) MaxLoop S} ≤ 1 / 2

    Whole-set rehash failure probability on any key set S of size ≤ n_max is at most 1 / 2.

  • step_rehash_prob_le (ks : List (Fin U)) (u : Fin U) : ks.Nodup → ks.length < n_max → u ∉ ks → μ.toOuterMeasure {θ : Θ | (pureReplay (h₁ θ) (h₂ θ) MaxLoop ks).isSome = true ∧ (pureReplay (h₁ θ) (h₂ θ) MaxLoop (ks ++ [u])).isNone = true} ≤ ↑C_reh / (max (↑n_max) 1 * max (↑MaxLoop) 1)

    One-step incremental rehash probability when appending a new key u ∉ ks to a duplicate-free key list ks of length < n_max is at most C_reh / (max n_max 1 * max MaxLoop 1).

theorem Cslib.DataStructure.Dictionary.CuckooHashing.IsCuckooHashPair.mono_consts {Θ : Type u_1} {μ : PMF Θ} {U m : ℕ} {h₁ h₂ : Θ → Fin U → Fin m} {n_max MaxLoop C_walk C_walk' C_reh C_reh' : ℕ} (hp : IsCuckooHashPair μ h₁ h₂ n_max MaxLoop C_walk C_reh) (hw : C_walk ≤ C_walk') (hr : C_reh ≤ C_reh') :
IsCuckooHashPair μ h₁ h₂ n_max MaxLoop C_walk' C_reh'

Monotonicity of IsCuckooHashPair in the constants C_walk and C_reh.

theorem Cslib.DataStructure.Dictionary.CuckooHashing.isCuckooHashPair_le_two {Θ : Type u_1} (μ : PMF Θ) {U m n_max MaxLoop : ℕ} (h₁ h₂ : Θ → Fin U → Fin m) (hn : n_max ≤ 2) (hloop : 0 < MaxLoop) :
IsCuckooHashPair μ h₁ h₂ n_max MaxLoop 1 0

Reusable hash-pair-independent IsCuckooHashPair instance for n_max ≤ 2 and 0 < MaxLoop (C_walk = 1, C_reh = 0) over any seed distribution μ and arbitrary hash pair (h₁, h₂) (without any independence assumption): inserting up to 2 keys into two tables T₁, T₂ always completes in 1 round with zero rehashes (even if both keys collide in T₁, the displaced first key is placed into an empty slot of T₂).