Documentation

CslibFrontier.Foundations.Combinatorics.PerfectHashFamily.LinearHash

Linear hashing on base-p digits #

For a prime p, a number x < q has D = ⌊log_p q⌋ + 1 digits xᵢ in base p. A seed a ∈ (ZMod p) ^ D gives the map x ↦ ∑ᵢ aᵢ xᵢ with values below p. Two distinct numbers below q differ in some digit, so they collide for exactly a 1 / p fraction of the seeds. By a union bound over the ordered pairs of distinct elements of a set S of numbers below q, fewer than p such pairs leave a seed whose map is injective on S.

This reduces a universe of size q to one of size p with at most p * q maps, and is the first step of the perfect hash family of CslibFrontier.Foundations.Combinatorics.PerfectHashFamily.Basic.

Main definitions #

Main results #

noncomputable def Cslib.linearHash (p q : ℕ) [Fact (Nat.Prime p)] :
Finset (ℕ → ℕ)

The linear hash maps from numbers below q to numbers below the prime p: a seed a ∈ (ZMod p) ^ D, where D = ⌊log_p q⌋ + 1, sends x to ∑ᵢ aᵢ xᵢ, where xᵢ are the base-p digits of x.

theorem Cslib.linearHash_lt {p q : ℕ} [Fact (Nat.Prime p)] {u : ℕ → ℕ} (hu : u ∈ linearHash p q) (x : ℕ) :
u x < p

The linear hash maps take values below p.

theorem Cslib.card_linearHash_le {p q : ℕ} [Fact (Nat.Prime p)] (hq : q ≠ 0) :
(linearHash p q).card ≤ p * q

There are at most p * q linear hash maps.

theorem Cslib.exists_injOn_linearHash {p q : ℕ} [Fact (Nat.Prime p)] {S : Finset ℕ} (hS : S ⊆ Finset.range q) (hp : S.offDiag.card < p) :
∃ u ∈ linearHash p q, Set.InjOn u ↑S

Some linear hash map is injective on a set of numbers below q that has fewer than p ordered pairs of distinct elements.