Word-RAM Cuckoo Hashing: Memory Layout, Lookup, and Bounded Eviction #
This module defines the contiguous Word-RAM memory layout, representation invariants, allocation and
initialization programs, deterministic two-probe lookup (probeKeyCode, queryCode), and bounded
two-table cuckoo displacement loop (evictLoopCode) for Pagh and Rodler's cuckoo hashing dictionary
[PR04] backed by the regime-switched hash family from
CslibFrontier.DataStructure.Dictionary.WordRAM.CuckooHashing.HashFamily [Tho13].
Main definitions #
Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.space,Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.spaceFactor: Word-RAM memory footprint in words and its linear scale factor inn_max + 1.Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.RepWithKeys,Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.Rep: insertion-order-indexed and existentially quantified Word-RAM representation invariants.Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.allocSpan,Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.initSetup: bump-allocation span and randomized header/hash initialization subroutines.Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.probeKeyCode,Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.queryCode,Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.queryStepsBound: deterministic two-table slot probing, dictionary lookup subroutine, andO_{c_exp}(1)lookup step bound.Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.evictLoopCode: bounded two-table cuckoo displacement loop.
Main results #
Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.space_le: the total Word-RAM footprint is at mostspaceFactor c_exp * (n_max + 1)words for every capacityn_max : ℕ.Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.Rep.unique,Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.Rep.supported: state uniqueness and memory-footprint framing forRep.Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.queryCode_execWithin,Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.querySteps_le: deterministic worst-case two-probe lookup specification preservingRepWithKeysand the in-memory seed, with step count at mostqueryStepsBound c_expunderU ≤ max n_max 4 ^ c_exp.Cslib.DataStructure.Dictionary.WordRAM.CuckooHashing.evictLoopCode_execWithin: deterministic execution specification relatingevictLoopCodetopureEvictandevictRounds.
References #
- R. Pagh and F. F. Rodler, "Cuckoo hashing" (8 December 2003 author manuscript, Section 2, pp. 3–10).
- M. Thorup, "Simple Tabulation, Fast Expanders, Double Tabulation, and High
Independence" (FOCS 2013, pp. 90–99;
arXiv:1311.3121v2, pp. 4–5, 11–13).
Section 1: Memory layout, slot encoding, and representation invariants #
Base address of the hash pair region [base + 20, t1Base base c_exp n_max).
Base address of the first cuckoo sub-table T₁ of size tableSize n_max.
Base address of the second cuckoo sub-table T₂ of size tableSize n_max.
Base address of the insertion-order key array insKeys[0 .. n_max - 1].
Base address of the insertion-order value array insVals[0 .. n_max - 1].
Total contiguous Word-RAM memory footprint [base, base + space c_exp n_max) in words.
Constant factor 20 + hashPairSpaceFactor c_exp + 514 bounding space c_exp n_max by
O_{c_exp}(n_max + 1) across all n_max : ℕ.
Total memory footprint space c_exp n_max is O_{c_exp}(n_max + 1): at most
spaceFactor c_exp * (n_max + 1) words for every n_max : ℕ.
Encode an optional SlotEntry U as a single machine word: 0 for none and e.idx + 1 for
some e.
Memory representation of the two cuckoo sub-tables T₁ (at t1Addr) and T₂ (at t2Addr).
Insertion-order-indexed representation invariant RepWithKeys w base c_exp n_max U V ks s x
for cuckoo hashing: stores the static header, the hash pair θ_mem = extractSeed ... x.mem, the
insertion-order key-value arrays ks for s, and a valid table placement tbl obtained by
replaying ks under θ_mem.
Representation invariant Rep w base c_exp n_max U V s x for cuckoo hashing.
A machine state x represents at most one abstract dictionary state s.
Rep depends only on reg 0 and the owned memory block [base, base + space c_exp n_max).
allocSpan program: sets reg 0 = base and advances reg 1 (frontierReg) to
base + space c_exp n_max.
Exact step bound for allocSpan.
Complete initSetup program for cuckoo hashing: populates the header, initializes the static
hash tables, samples the initial cuckoo hash pair (h₁, h₂), and restores base and
frontierReg.
Exact step bound for initSetup.
Couples a state distribution μ : PMF (Data 19) with its extracted in-memory seed.
Coupled distributional specification for initSetup, directly returning the seed-coupled
initial distribution ν₀.
Section 3: Base-shifted hash wrappers, probeKeyCode, and queryCode #
Resamples (h₁, h₂) with reg 0 = base and restores reg 0 = base.
Step bound for resampleAtBaseCode.
Distributional execution specification for resampleAtBaseCode.
Helper subprogram that loads mem[base + off] into reg dst using reg 15 as scratch.
Helper subprogram that stores reg src into mem[base + off] using reg 15, 16 as scratch.
Helper subprogram that stores constant val into mem[base + off] using reg 15, 16, 18 as
scratch.
Branches on 0 < mem[base + off] using reg 15, 16 as scratch.
Every entry in tbl comes from ks at its recorded index e.idx.
Two-probe cuckoo lookup (probeKeyCode): probes T₁[h₁(u)], and if u is not found in T₁,
probes T₂[h₂(u)]. Stores foundFlag ∈ {0, 1} in mem[base + 13] and foundIdx in
mem[base + 14].
Step bound for probeKeyCode.
Lookup operation (queryCode): stores u.val from reg 3 into mem[base + 11], runs
probeKeyCode, and writes encodeOptionNat (s u) into reg 2.
Step bound for queryCode.
Section 4: Bounded cuckoo eviction loop (putTableSlotCode, evictLoopCode) #
Bounded cuckoo eviction loop (evictLoopCode): executes up to remFuel = mem[base + 15]
displacement rounds starting from (curKey = mem[base + 11], curIdx = mem[base + 12]) with
activeFlag = mem[base + 16] = 1.
Step bound per displacement round in evictLoopCode.
Deterministic execution specification for evictLoopCode, bounding steps in terms of
evictRounds and relating the post-state to pureEvict.
Step-bound inequalities for probeKeyCode, queryCode, and evictLoopCode #
O(c_exp⁴) = O_{c_exp}(1) worst-case step bound for queryCode c_exp n_max, independent of
n_max and U whenever U ≤ max n_max 4 ^ c_exp.