Self-contained Word-RAM multiply-shift hashing #
This file implements the multiply-shift universal hash family of Dietzfelbinger, Hagerup,
Katajainen, and Penttonen [DHKP97] as a self-contained pair
of structured Word-RAM programs over Cslib.WordRAM.Basis.exact:
Cslib.Algorithms.WordRAM.Hashing.MultiplyShift.initCode w₀: samples a uniform seedb ∈ [0, 2 ^ (w₀ - 1) - 1]into registerregBin2instructions and1Instr.randcall.Cslib.Algorithms.WordRAM.Hashing.MultiplyShift.evalCode w₀ M: deterministically computes((2 * b + 1) * x % 2 ^ w₀) / 2 ^ (w₀ - M)in registerregOutfrom seedbinregBand keyxinregXin9instructions (0randcalls) without intermediate word overflow whenever0 < w₀,M ≤ w₀, and2 * w₀ ≤ w.
We prove that initCode w₀ induces the exact uniform distribution
PMF.uniformOfFintype (Fin (2 ^ (w₀ - 1))) on the seed register regB, that evalCode w₀ M
computes Cslib.Probability.multiplyShift w₀ M b x, and hence that the Word-RAM evaluation map is
(2 / 2 ^ M)-universal (isUniversalHash_evalData).
Main definitions #
regB,regX,regOut,regT1,regT2: register layout inFin 5.initCode,initComp: seed-sampling code and its exactProbCompsemantics.evalCode,evalData: deterministic evaluation code and its closed-form finalData 5.
Main results #
initCode_execRand,initCode_execRandWithin: exact and Hoare-style execution ofinitCode.map_extractSeed_eval_initComp: the seed sampled byinitCodehas distributionPMF.uniformOfFintype (Fin (2 ^ (w₀ - 1))).evalCode_exec,evalCode_execWithin: exact9-instruction execution ofevalCodecomputingCslib.Probability.multiplyShift w₀ M.isUniversalHash_evalData: the hash family computed in registerregOutbyevalCodeunder the seed distribution ofinitCodeis(2 / 2 ^ M)-universal.
References #
Register 0: holds the sampled seed b < 2 ^ (w₀ - 1).
Instances For
Register 1: holds the input key x < 2 ^ w₀.
Instances For
Register 2: receives the M-bit hash value multiplyShift w₀ M b x.
Instances For
Register 3: first scratch register.
Instances For
Register 4: second scratch register.
Instances For
Structured Word-RAM program that initializes the multiply-shift seed b ∈ [0, 2 ^ (w₀ - 1) - 1]
in regB using 2 instructions and 1 rand call.
Instances For
Closed-form machine data after initCode w₀ samples k.
Instances For
Exact ProbComp computation induced by initCode w₀ from initial data d.
Instances For
When w₀ ≤ w, initCode w₀ executes cleanly in 2 instructions and 1 rand call with exact
ProbComp semantics initComp w₀ d.
Hoare-style specification for initCode w₀: runs in 2 steps and 1 rand call, placing a
seed < 2 ^ (w₀ - 1) in regB while preserving regX, regOut, and memory.
Extracting the seed < 2 ^ (w₀ - 1) from register regB of a machine state d', defaulting to
0 outside the valid range.
Instances For
Uniformity of the sampled seed: the distribution of extractSeed w₀ z.1 under
(initComp w₀ d).eval is the exact uniform distribution
PMF.uniformOfFintype (Fin (2 ^ (w₀ - 1))).
Structured Word-RAM program that evaluates multiplyShift w₀ M in 9 deterministic
instructions (0 rand calls), reading b from regB and x from regX and writing the hash
value into regOut.
Instances For
Closed-form final machine data produced by evalCode w₀ M from d.
Instances For
The output register regOut of evalData w₀ M d equals
Cslib.Probability.multiplyShift w₀ M.
Exact 9-instruction execution of evalCode w₀ M without intermediate word overflow when
0 < w₀, 2 * w₀ ≤ w, d.regs regB < 2 ^ (w₀ - 1), and d.regs regX < 2 ^ w₀.
Bounded-time execution corollary for evalCode w₀ M (9 instructions).
Universal hashing guarantee for the Word-RAM multiply-shift implementation:
under the seed distribution of initCode w₀, the hash function mapping x : Fin (2 ^ w₀) to the
output register regOut of evalData w₀ M is (2 / 2 ^ M)-universal whenever 0 < w₀ and
M ≤ w₀.