opthash
Rust implementations of Elastic Hashing and Funnel Hashing from Optimal Bounds for Open Addressing Without Reordering (Farach-Colton, Krapivin, Kuszmaul, 2025).
Both are open-addressing hash maps that achieve optimal expected probe complexity without reordering elements after insertion.
Data Structures
Both maps share a common core: RawTable-backed multi-level layouts, 7-bit fingerprint control bytes, SIMD control-byte scans for occupancy + lookup, tombstone accounting, and per-level Lemire fastmod magics for the hash → slot mapping. The default BuildHasher is foldhash.
ElasticHashMap<K, V>— FlatRawTableper level wsith geometrically halving capacities; insertion uses per-level probe budgets + coprime group steps.FunnelHashMap<K, V>— Bucketed levels plus a split special array:primary(group-probed) andfallback(two-choice buckets).
Both support insert, get, get_mut, contains_key, remove, and clear. Maps start with zero allocation (new()) and grow dynamically on demand. Advanced tuning is available through ElasticOptions, FunnelOptions, and with_options(...).
Usage
Rust
use ;
let mut map = new;
map.insert;
assert_eq!;
let mut map = with_options;
map.insert;
assert_eq!;
let mut map = with_options;
map.insert;
assert_eq!;
Python
=
= 42
assert == 42
assert in and == 1
=
=
Layout Sketch
RawTable (shared by both maps)
==============================
fp = fingerprint (7-bit control byte)
kv = key-value entry, __ = empty, xx = tombstone
Single allocation, slots first, controls at the end:
data_ptr ► [kv][kv][ ][kv][ ][kv]... [pad] [fp][fp][__][xx][__][fp]...
└──── slots (T-aligned) ────┘ └─ controls (16-aligned) ──┘
▲ ctrl_offset
No per-group metadata. Occupancy is derived from SIMD scans of the control bytes
(eq_mask_16 for fingerprints, free_mask_16 for free slots).
ElasticHashMap
==============
levels: Vec<Level>
Level 0 RawTable (largest, ~half of total capacity)
Level 1 RawTable (geometrically halved)
Level 2 ...
per-level len, tombstones, half_reserve_slot_threshold,
limited_probe_budgets, group_steps, salt,
group_count_magic, step_count_magic
table-wide len, capacity, max_insertions, reserve_fraction,
probe_scale, batch_plan, current_batch_index,
batch_remaining, max_populated_level, hash_builder
FunnelHashMap
=============
levels: Vec<BucketLevel>
Level 0
slots: kv kv __ __ ... kv kv __ __ ... kv ...
controls: fp fp __ __ ... fp fp __ __ ... fp ...
└── bucket 0 ──┘└── bucket 1 ──┘
Level 1 (same layout, smaller buckets)
...
per-level len, tombstones, bucket_size, bucket_count,
salt, bucket_count_magic
special: SpecialArray
primary RawTable, group-probed (like elastic)
(paper B) len, group_summaries, group_tombstones, group_steps
fallback RawTable, two-choice bucketed
(paper C) len, tombstones, bucket_size, bucket_count
table-wide len, capacity, max_insertions, reserve_fraction,
primary_probe_limit, max_populated_level, hash_builder
Benchmarks
See benches/README.md for bench target layout, charts, CLI flags, chart regeneration, and flamegraph profiling.