A prefix-ordered hash map for Rust: a flat open-addressing table kept
globally sorted by hash, with each entry's home slot derived from its hash
prefix (top bits). no_std + alloc compatible.
The determinism contract: (1) iteration order is deterministic regardless
of insertion order, always; (2) after compact(), content-equal maps have
identical bytes. No unordered hash map offers either.
One invariant — global hash order survives growth (the prefix map is monotone in the hash) — pays repeatedly:
- Deterministic iteration order (by hash), independent of insertion order.
- One-cache-line probes: the full 64-bit hash lives inline with its (K, V),
so a lookup touches one contiguous region and terminates at the first stored
hash greater than the target (
u64::MAXdoubles as the empty sentinel). - Comparison-free streaming resize: rehash is a single sequential pass with a monotone write cursor — no re-hashing (the hash is stored), no re-sorting, no scatter. With expensive-to-hash keys (strings, paths, composites) this inverts resize-heavy workloads outright.
- Canonical representation on demand:
compact()repacks into the minimal table with layout a pure function of contents — content-equal maps are byte-identical after compaction, whatever their histories (memcmp-tested). - Streaming set algebra:
union/intersection/difference/symmetric_difference(and| & - ^,append) are O(n+m) sorted merges with compact-canonical outputs — no probing, and no re-hashing, which makes them faster than clone+extend once keys are expensive to hash (measured: 0.90× hashbrown with 128-B String keys; near-parity at 1M disjoint u64, where clone+extend is nearly a memcpy). - The map itself is
Eq,Ord,PartialOrd, andHash: canonical iteration order makes map-level comparison and hashing lawful — maps as keys in maps, sets of maps,sort()able collections of maps. Key comparisons execute only to canonicalize full 64-bit hash collisions (≈ n²/2⁶⁵ — never on any probe, lookup, or resize path).
Measured highlights (vs hashbrown, in-run, Apple M5 Max; see docs/findings.md for the full multi-platform story and every caveat)
| workload | ratio (lower = pomap faster) |
|---|---|
point reads (get, hot-set, update) |
0.56–0.60× |
| whole-map iteration @ 1M | 0.61× |
build from empty (u64 keys, GROWTH=8 / 4) |
0.88× / ~1.0× |
build / shrink / remove (String keys, GROWTH=4) |
0.71× / 0.35× / 0.74× |
| misses, warm removes, pre-provisioned inserts | 0.9–1.8× (the order-maintenance tax) |
| memory (bytes/entry, avg) | ~2.0× (G2) – 2.8× (G4) |
Cold-access behavior, four-platform results (Apple M3/M5, AMD EPYC Zen 4
bare-metal, Zen 5c VM), perf-counter mechanisms, the design-space Pareto
frontier across seven sibling engines, and all negative results are documented
in docs/findings.md — the working draft toward a paper.
use pomap::PoMap;
let mut map: PoMap<u64, u64> = PoMap::new();
map.insert(1, 10);
assert_eq!(map.get(&1), Some(&10));
// Deterministic iteration order (hash order), regardless of insertion order.
for (k, v) in map.iter() { /* ... */ }
// Provision so n inserts trigger zero grows (hashbrown-compatible contract):
let mut m: PoMap<u64, u64> = PoMap::with_capacity(1_000_000);The growth factor is a const generic dial (power of two, default 4):
use core::hash::BuildHasherDefault;
type Fast = pomap::PoMap<u64, u64, BuildHasherDefault<ahash::AHasher>, 8>; // fastest builds
type Lean = pomap::PoMap<u64, u64, BuildHasherDefault<ahash::AHasher>, 2>; // leanest memoryFeature flags: std (default; disable for no_std + alloc), serde
(Serialize/Deserialize — equal maps serialize to identical bytes, the
determinism contract on the wire), tui (the bench_graph explorer),
bench-string (String-payload benchmarks), growth2 (bench the GROWTH=2
configuration).
| target | what it measures |
|---|---|
pomap_bench |
the 9-group main suite vs hashbrown/std (canonical, cross-machine) |
cold.rs |
per-size cold-access matrix (value size × working set × op) |
family_bench |
all seven historical engine designs under one harness |
loop_bench |
optimizer A/B: live engine vs frozen pre-optimization snapshot |
iter_bench |
whole-map iteration vs hashbrown/std/BTreeMap |
audit_bench |
methodology probes (thermal state, RNG dilution) |
cold_perf |
hardware-counter runs (Linux perf) |
scripts/collect_paper.sh runs the full per-machine collection with
spec-named outputs; scripts/collect_all.sh is the shorter classic set.
Numbers are only comparable within a run (normalize to the in-run
hashbrown anchor); see docs/findings.md §4 for methodology.
Production-grade surface, research-grade provenance: Miri-clean (zero
UB findings across the 52-test subset covering every unsafe path; the
multi-minute fuzz tests run under the native harness), fuzzed against
std::HashMap (50k-op randomized runs, both growth factors, u64 and
String payloads), adversarial-hasher hardened (total-collision and
tail-clustering tests guard the no-bounds-check probe invariant), and
clippy/doc clean. Full HashMap API parity — entry(), Borrow<Q> lookups
(query a String map by &str), get_disjoint_mut, double-ended canonical
iteration, From<[(K, V); N]>, retain/drain/reserve/try_reserve —
plus the determinism extras: compact(), first/last_key_value,
pop_first/pop_last, streaming set algebra, map-level Eq/Ord/Hash,
and canonical serde (feature-gated).