Skip to main content

Crate kevy_hash

Crate kevy_hash 

Source
Expand description

kevy-hash — fast, well-distributed hashing for kevy’s single-trust-domain keyspace. Zero dependencies.

std’s HashMap is a hashbrown Swiss table (excellent — kevy keeps it) keyed by SipHash-1-3 (DoS-resistant, but a tax a single-threaded-per-shard keyspace facing no adversarial cross-trust key collisions does not need). This crate supplies the hasher that table should use instead: an FxHash-style word-at-a-time absorb plus a murmur3 fmix64 avalanche finalizer.

Measured (via kevy-store/examples/bench_keyspace.rs): ~4× faster hashing, ~1.2–2.8× faster GET-hit, ~1.1–1.7× faster GET-miss than SipHash, with no clustering. The finalizer is essential — the bare Fx absorb (no fmix64) clusters 30–50× on low-entropy sequential keys like "key:0".."key:99999".

Not DoS-resistant. There is no random seed, so an attacker who can choose keys and observe timing could force collisions. kevy’s keyspace lives inside one trust domain per shard, so this is the right trade; do not reuse this hasher for maps fed untrusted, adversarially-chosen keys across a trust boundary.

use kevy_hash::FxHashMap;

let mut m: FxHashMap<Vec<u8>, u64> = FxHashMap::default();
m.insert(b"key".to_vec(), 1);
assert_eq!(m.get(b"key".as_slice()), Some(&1));

Structs§

FxHasher
Fast, well-distributed Hasher for kevy’s keyspace. Word-at-a-time absorb (FxHash-style) finished with fmix64. See the crate docs for the security trade-off.

Traits§

KevyHash
Single-call hashing for kevy’s per-command hot path.

Functions§

crc16
CRC16-CCITT (XMODEM) of bytes. Check vector: crc16(b"123456789") == 0x31C3.
fmix64
murmur3 fmix64 avalanche — spreads every input bit across all 64 output bits. ~6 ALU ops, applied once on Hasher::finish. This is what the bare Fx absorb lacks, and why it clusters without it.
key_hash_slot
The Redis-cluster hash slot of key: crc16(hashtag(key)) & 16383.

Type Aliases§

FxBuildHasher
BuildHasher for FxHasher. Seedless, so equal keys hash equally across instances and process runs.
FxHashMap
A HashMap using FxHasher instead of SipHash.
FxHashSet
A HashSet using FxHasher instead of SipHash.