pub trait KevyHash {
// Required method
fn kevy_hash(&self) -> u64;
}Expand description
Single-call hashing for kevy’s per-command hot path.
std::hash::Hasher is a state-machine API — every hash is Hasher::default()
→ write_* → finish, with BuildHasher indirection on top. For
kevy-map’s open-addressing table the keyspace is a small handful of
well-known leaf types ([u8], u32, u64, i32); we get a faster, inline-
friendly hash by exposing one method on each that produces the final mixed
64-bit value in one go.
The integer impls agree with feeding the value through
FxHasher and calling finish, so for those the trait is a
dispatch shortcut and nothing more. The [u8] impl does not — it
takes the two-stream pipelined path, and its own documentation says
so.
That distinction used to be stated as “all impls must agree”, forty
lines above the note admitting one of them does not. This is not a
typo to tidy: the sentence declared exactly the property that makes
mixing the two safe, so a caller who used FxHashMap in one place
and kevy_hash() in another and compared across them would have been
silently wrong, on the strength of a guarantee written here.
kevy-map consumes both the full hash (for bucket index) and its top
7 bits (for the metadata byte).
§Examples
The point of the trait is that a leaf type hashes in one call, with no
Hasher to build and no dispatch to pay:
use kevy_hash::KevyHash;
assert_ne!(1u64.kevy_hash(), 2u64.kevy_hash());
assert_ne!(b"a"[..].kevy_hash(), b"b"[..].kevy_hash());The integer impls agree with routing the same value through
FxHasher, which is what lets the dispatch be cut without changing
the hash:
use core::hash::Hasher;
use kevy_hash::{FxHasher, KevyHash};
let mut h = FxHasher::default();
h.write_u64(0x0123_4567_89ab_cdef);
assert_eq!(0x0123_4567_89ab_cdefu64.kevy_hash(), h.finish());Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl KevyHash for [u8]
impl KevyHash for [u8]
Source§fn kevy_hash(&self) -> u64
fn kevy_hash(&self) -> u64
Byte-slice hash. Uses the two-stream pipelined path internally
for ILP on the bench’s 8-64 byte keyspace, closing the prior 1 ns
gap vs rustc-hash 2.x’s hash_bytes. The final fmix64 retains
the anti-clustering guarantee that the
no_catastrophic_clustering_on_low_entropy_keys test enforces.
Note: the result diverges from the legacy FxHasher absorb path —
callers using FxHashMap<Vec<u8>, _> route through std’s
Hash::hash → Hasher::write → finish (the legacy single-stream
path), which intentionally stays put for cross-instance hash
stability with anything that depended on the v0.polish bit pattern.
The KevyHash for [u8] impl is for one-call hot paths like
kevy-map::find_by_borrow, which is the only one we measure.