Skip to main content
← CONCEPTS / ALGORITHMS-DATA-STRUCTURES
An end-to-end domain learning journey

SwissTable & SIMD Control-Byte Hash
Maps (Abseil / Rust hashbrown).

Chained hash maps chase heap pointers and scalar linear probing checks one slot per cycle; SwissTables pack 7-bit H2 fingerprints into 16-byte control arrays to probe 16 slots in one SIMD instruction.
Start the journey2 sections· Last modified Dec 3, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When implementing SwissTable, reset deleted slots to EMPTY if the group already has an EMPTY slot to avoid tombstones.

TL;DR30-second simplified summary
▾

Sustains 87.5% load factor and 2x faster lookups than chained maps.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Open Addressing & Linear Probing
Stores entries inline in a flat array to avoid linked-list pointers.
SIMD Vector Instructions (SSE2 / NEON)
Operates on 16 bytes in parallel within a single CPU register.
Full walkthrough · 2 stages
01
STAGE 01intermediate

H1/H2 Splitting & 16-Byte Control Groups.

Why this matters: Filter 16 slots in 1 CPU cycle before touching key memory.

H1 picks the 16-slot group; H2 (7 bits, 0x00..0x7F) is compared in parallel against 16 control bytes. Negative control bytes encode EMPTY (0x80) and DELETED (0xFE).

Before · Chained / Scalar Probing
After · SwissTable 16-Way SIMD
ChoiceWhat it buysWhat it costs
Chained HashMapSimple tombstonesHeap pointer chasing; L1 misses
SwissTable (16-Byte SIMD)16-way parallel probe; 87.5% loadRequires SIMD intrinsics / 16B alignment
CTRL_EMPTY, CTRL_DELETED = 0x80, 0xFE

def probe_group(ctrl_bytes: list, h2: int):
    # Simulates _mm_cmpeq_epi8 + _mm_movemask_epi8 across 16 control bytes
    matches = [i for i, c in enumerate(ctrl_bytes) if c == h2]
    has_empty = any(c == CTRL_EMPTY for c in ctrl_bytes)
    return matches, has_empty
02
STAGE 02advanced

Tombstone-Free Deletes & Java Bitwise Emulation.

Why this matters: Prevent probe-chain degradation under heavy delete churn.

If the 16-slot group already contains an EMPTY byte, deletion resets the slot directly to EMPTY instead of DELETED, avoiding tombstone accumulation.

Engineering Decision Framework
Problem
How to sustain <10 ns lookups at 87.5% load factor without linked-list cache misses or scalar probe loops.
Naive Solution
Use separate chaining or scalar linear probing comparing full keys one slot at a time.
Why It Fails
Chaining chases heap pointers across cache lines; scalar probing triggers unpredictable branch mispredictions on every collision.
Alternatives
Separate chaining, Robin Hood scalar probing, or SwissTable 16-byte SIMD control arrays.
Engineering Decision
Store 7-bit H2 fingerprints in a 16-byte control array and match all 16 slots in parallel via SIMD before accessing the key array.
Trade-Offs
Adds 1 byte of control metadata per slot, but doubles lookup speed and eliminates 99.2% of unnecessary key comparisons.
Decision Exercise · Make the Call

Why does SwissTable delete directly to EMPTY (instead of DELETED) whenever the 16-slot group already contains an EMPTY slot?

public static int matchByteMask(long word8, int h2) {
    // SWAR (SIMD Within A Register) 8-byte parallel control-byte match
    long broadcast = (h2 & 0xFFL) * 0x0101010101010101L;
    long x = word8 ^ broadcast;
    long hasZero = (x - 0x0101010101010101L) & ~x & 0x8080808080808080L;
    return Long.numberOfTrailingZeros(hasZero) >>> 3;
}
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

What does the 7-bit H2 fingerprint in SwissTable's control byte achieve?

Recommended Learning Flow