Universe-Reduced Salted General-q Bit-Packed Double Tabulation ([Thorup2013]) #
This module provides a Word-RAM implementation of universe-reduced salted general-q double
tabulation hashing with bit-packed lookup tables:
- Stage 1 (
multiplyShiftReducedviaoddMulModWord): maps any keyu : Fin U(U ≤ 2 ^ w₀,0 < w₀ ≤ w) to a reduced keyrKey ∈ Fin (2 ^ min w₀ R)without2 * w₀ ≤ woverflow, failing injectivity on a windowW_set : Finset (Fin U)with probability at most(#W_set * (#W_set - 1)) / 2 ^ R. - Stage 2 (salted general-
qdoubleTabHashwith bit-packed tables): appends a salt characters : Fin s_max(s_max ≤ 2 ^ b_char) to thec_tabbase-2 ^ b_charcharacters ofrKey(min w₀ R ≤ c_tab * b_char) and evaluates(c_tab + 1, d, b_char, M_out)double tabulation withd = 2 * q * (c_tab + 1). BothT₁((c_tab + 1) * d * 2 ^ b_charentries ofb_charbits) andT₂(d * 2 ^ b_charentries ofM_outbits) are stored inBitPackedArrays so the total footprint is≤ (((c_tab + 1) * d * b_char + d * M_out) * 2 ^ b_char + w - 1) / w + 6words for every word widthw > 0(includingw ≫ n_max). - Exact uniform resampling (
resampleCode) andMemory.Progevaluation (evalGenProg):resampleCodepopulates(α, T₁, T₂)from the exact uniform distribution inO((topWords + botWords) + 1)instructions viaTabulation.randFillLoop, andevalGenProgevaluates the hash inO(c_tab * d)deterministic instructions viaMemory.Progandrealize(¬ReadsWidth, single compiledCode .exactindependent of(c_tab, d, b_char, M_out, U, w)).
Main definitions #
Cslib.DataStructure.HashFamily.WordRAM.BitPackedDoubleTabulation.space,topWords,botWords,Seed,saltedChars,evalSalted,GoodTop.Cslib.DataStructure.HashFamily.WordRAM.BitPackedDoubleTabulation.extractSeed,SeedRep,resampleCode,resampleSteps.Cslib.DataStructure.HashFamily.WordRAM.BitPackedDoubleTabulation.HashParams,mkHashParams,evalGenProg,evalProg.
Main results #
space_le: bit-packed word-space bound valid for allw > 0.isKWiseIndependentHash_evalSalted_of_goodTop: conditional exactk-wise independence onFin s_max × W_setwheneverGoodTopholds.toOuterMeasure_not_goodTop_le: explicit union bound on¬ GoodTopcombiningtoOuterMeasure_not_injOn_multiplyShiftReduced_leandcard_not_isKUnique_le.resampleCode_execRand,map_extractSeed_eval_resampleComp: exactExecRandsemantics and product uniformity of bit-packed seed resampling.realizes_evalGen,evalProg_spec,validHistory_evalProg,memoryCost_evalProg:Realizes .exactcertificate, functional correctness, memory admissibility, and cost ofevalProg.
References #
Section 1: Salted double-tabulation model, conditional k-wise independence, and layout #
Number of entries (c_tab + 1) * d * 2 ^ b_char in the top-level bit-packed table T₁.
Number of entries d * 2 ^ b_char in the bottom-level bit-packed table T₂.
Number of w-bit words storing T₁ as a BitPackedArray of b_char-bit entries.
Number of w-bit words storing T₂ as a BitPackedArray of M_out-bit entries.
Word offset 1 + topWords w c_tab d b_char of the bottom-level bit-packed table T₂.
Bit-packed word bound valid for every word width w:
space w c_tab d b_char M_out ≤ (topEntries * b_char + botEntries * M_out + w - 1) / w + 6.
Combined seed type (α, T₁, T₂) for universe-reduced salted double tabulation.
Extract Stage 2 top table T₁ from seed.
Extract Stage 2 bottom table T₂ from seed.
Salted (c_tab + 1)-character tuple: the first c_tab characters extract base-2 ^ b_char
digits of the reduced key rKey, and the final character at index c_tab encodes the salt s.
Injectivity of saltedChars when s_max ≤ 2 ^ b_char and R' ≤ 2 ^ (c_tab * b_char).
Good top-seed event on a key window W_set : Finset (Fin U): Stage 1 multiplyShiftReduced is
injective on W_set and Stage 2 simpleTabTuple T₁ is k-unique.
Conditional exact k-wise independence on Fin s_max × W_set:
whenever s_max ≤ 2 ^ b_char, min w₀ R ≤ c_tab * b_char, and GoodTop holds for (α, T₁),
the bottom-table family T₂ ↦ evalSalted ... (α, T₁, T₂) restricted to Fin s_max × W_set is
exact k-wise independent.
Probability bound on ¬ IsKUnique k (simpleTabTuple T₁) under PMF.uniformOfFintype, lifted
from Cslib.Probability.card_not_isKUnique_le.
Explicit failure-probability bound on ¬ GoodTop:
for a uniform seed θ : Seed w₀ c_tab d b_char M_out, when 0 < w₀, U ≤ 2 ^ w₀, 1 ≤ q,
d = 2 * q * (c_tab + 1), and 2 * doubleTabCodeBound (c_tab + 1) d q k ≤ 2 ^ ((q - 1) * b_char),
the probability that GoodTop U w₀ R c_tab d b_char k W_set θ.1 θ.2.1 fails is at most
(#W_set * (#W_set - 1)) / 2 ^ R + 2 * (doubleTabCodeBound (c_tab + 1) d q k) ^ 2 / (2 ^ ((q - 1) * b_char)) ^ 2.
Section 2: Bit-packed slice uniformity, SeedRep, and resampleCode #
For 0 < w and idx < N, every bit index idx * k + j (j < k) lies in word
(idx * k + j) / w < packedWords N k w.
Exact bit-level characterization of readPacked: for 0 < w, k ≤ w, and j < k, bit j of
readPacked arrBase k w mem idx equals bit (idx * k + j) % w of word
mem (arrBase + (idx * k + j) / w).
Additive homomorphism projecting packedWords N k w w-bit strings onto N k-bit strings
by reading bits [idx * k, (idx + 1) * k).
Map from a raw w-bit word slice Fin (packedWords N k w) → Fin (2 ^ w) to
Fin N → Fin (2 ^ k) matching extractPackedSlice.
Pushforward of PMF.uniformOfFintype (Fin (packedWords N k w) → Fin (2 ^ w)) along
packedSliceOfWords is PMF.uniformOfFintype (Fin N → Fin (2 ^ k)).
Congruence of SeedRep under memory updates preserving [base, base + space).
Single-pass randFillLoop seed resampling (resampleCode) #
Structured Word-RAM program on Data 12 (keeping reg 0 = base) that samples (α, T₁, T₂)
into [base, base + space w c_tab d b_char M_out).
Instruction count 5 * (topWords + botWords) + 10 of resampleCode.
Explicit ProbComp (Data 12 × ℕ) induced by resampleCode.
Pathwise postcondition of resampleComp: executes in resampleSteps instructions, preserves
reg 0 = base, establishes SeedRep, preserves Bounded w, and modifies only
[base, base + space).
Exact product uniformity of resampleComp: when 0 < w, b_char ≤ w, and M_out ≤ w,
the extracted seed extractSeed base w w₀ c_tab d b_char M_out z.1.mem under resampleComp has
exact uniform distribution PMF.uniformOfFintype (Seed w₀ c_tab d b_char M_out).
Section 3: Memory.Prog + realize deterministic O(c_tab * d) evaluation #
Runtime register block of 16 precomputed hash parameters for parameter-free Realizes.
Instances For
Construct the 16-word parameter vector for (w, w₀, R, c_tab, d, b_char, M_out).
Word width $w$ in the hash parameter vector.
Shift count $w₀ - R$ in the hash parameter vector.
Half-chunk bitwidth $\lfloor(w₀ - 1) / 2\rfloor$ in the hash parameter vector.
Double half-chunk bitwidth $2 \lfloor(w₀ - 1) / 2\rfloor$ in the hash parameter vector.
Low chunk mask $2^{w₀ - 1} - 1$ in the hash parameter vector.
First half-chunk mask in the hash parameter vector.
Second half-chunk mask in the hash parameter vector.
Top remainder bit mask in the hash parameter vector.
Character bitwidth $b$ in the hash parameter vector.
Character mask $2^b - 1$ in the hash parameter vector.
Character radix $2^b$ in the hash parameter vector.
Output word count $M_{\mathrm{out}}$ in the hash parameter vector.
Memory word offset of bottom table in the hash parameter vector.
Chunk count plus one ($c_{\mathrm{tab}} + 1$) in the hash parameter vector.
Chunk count $c_{\mathrm{tab}}$ in the hash parameter vector.
Dimension $d$ in the hash parameter vector.
Well-formedness envelope for HashParams at base on a w-bit machine.
Fit of all 16 words in mkHashParams under HashEnv.
Inner-loop body (p = ((hp, (base, j)), ((i, y_acc), r_cur))): extracts character i from
r_cur, reads T₁[i, j, ch], XORs into y_acc, and shifts r_cur right by b_char.
Precondition for innerStepGenProg.
Outer-loop body (p = ((hp, (base, (s_val, rKey))), (j, out_acc))): computes y_j across all
c_tab + 1 characters, reads T₂[j, y_j], and XORs into out_acc.
Loop-safety, state-preservation, and accumulator-range invariant for innerStepGenProg.
Parameter-free wrapper for iterate outerStepGenProg.
Parameter-free Memory.Prog hash evaluation (p = (hp, ((base, s_val), u_val))):
computes rKey = oddMulModWord w₀ (s.mem base) u_val >>> (w₀ - R) and evaluates (c_tab + 1, d)
bit-packed double tabulation in O(c_tab * d) deterministic steps.
Precondition for evalGenProg.
Parameter-free Realizes .exact certificate for evalGenProg (¬ReadsWidth, single compiled
Code .exact).
Exact functional correctness and state preservation of evalProg:
under SeedRep, evalProg leaves s unchanged and returns (evalSalted ... θ (salt, u)).val.
Exact memoryCost of evalProg: 1 + 2 * d * (c_tab + 2) (O(c_tab * d)).
Memory history admissibility (ValidHistory) for evalGenProg under EvalGenPre and
base + space ≤ s.frontier.
Specialized ValidHistory lemma for evalProg.