Overview
An open-addressed hash table implementing Celis Robin Hood displacement, early-exit lookups on PSL ordering, and tombstone-free backward-shift deletion.
Guided Implementation Walkthrough (4 Progressive Steps)
Step 1: Probe Sequence Length (PSL) Arithmetic on Power-of-2 Ring
- Core Mechanical Concept: Measuring Cyclic Probe Distance via Bitmask Subtraction
- Target Module:
index.js(RobinHoodHashMap._psl) - Engineering Specification: Implement
_psl(slotIdx, idealIdx)to compute how many linear probes an entry atslotIdxhas traveled fromidealIdx. In a power-of-two table,(slotIdx - idealIdx) & this._maskhandles wrap-around across index0in $O(1)$ without branches. - Verification Invariant: computes cyclic probe sequence length across wrap-around
Step 2: Robin Hood Displacement Insertion
- Core Mechanical Concept: Stealing Slots from "Rich" Keys (Small PSL) to Give to "Poor" Keys (Large PSL)
- Target Module:
index.js(RobinHoodHashMap.set) - Engineering Specification: Implement
set(key, value)with Robin Hood swap semantics. 1. If(this._size + 1) > this._capacity * this._maxLoad, double capacity viathis._resize(this._capacity * 2). 2. Walk linearly fromidx = this._idealIndex(key). Ifcur.key === entry.key, overwritecur.value. 3. Ifentry.psl > cur.psl, swapentryandthis._slots[idx]and continue probing with the displaced entry. - Verification Invariant: inserts keys and bounds PSL variance via Robin Hood displacement
Step 3: Early-Exit Lookup on PSL Monotonicity
- Core Mechanical Concept: Aborting Unsuccessful Searches When currentPSL > occupantPSL
- Target Module:
index.js(RobinHoodHashMap.get) - Engineering Specification: Implement
get(key)with early termination. Because Robin Hood insertion guarantees that any key with a largerpslwould have displaced an occupant with a smallercur.psl, ifcur === null || psl > cur.psl, the target key cannot exist further down the probe chain. - Verification Invariant: terminates lookups early when probe distance exceeds occupant PSL
Step 4: Tombstone-Free Backward-Shift Deletion
- Core Mechanical Concept: Healing Probe Chains by Shifting Displaced Neighbors Left
- Target Module:
index.js(RobinHoodHashMap.delete) - Engineering Specification: Implement
delete(key)using backward-shift deletion instead of tombstones. 1. Locatekeyatidx(returningfalseif absent). 2. Clearthis._slots[idx] = nulland decrementthis._size. 3. Whilenext = (prev + 1) & _maskis occupied andthis._slots[next].psl > 0, shiftthis._slots[next]intoprev, decrement itspsl, and advance. - Verification Invariant: deletes keys via backward-shift without leaving tombstones
Asymptotic & Memory Layout Guarantees
- Category: Hashing & Sketches
- Difficulty: Advanced (~35 minutes)
- Key Architectural Highlights:
• Probe Sequence Length (PSL) displacement minimizing probe variance
• Early-exit search termination when current PSL exceeds occupant PSL
• Tombstone-free backward-shift deletion preventing probe degradation - Tags & Primitives:
Robin Hood Hashing,Open Addressing,Backward-Shift Delete,PSL Variance,FNV-1a
Production Systems Context & Verification
This from-scratch implementation is engineered with zero external dependencies and deterministic verification harnesses. Every internal invariant—from pointer restoration and bitmask addressing to amortized potential bounds and tree height balance—is asserted directly in test.js. Use the interactive browser workbench above to complete the guided steps in Guided Lab mode or inspect and benchmark the complete reference architecture in Full Solution mode.