pub struct FastHasher { /* private fields */ }Expand description
Faster non-cryptographic hasher for small integer keys.
Intended to replace and outperform the default SipHash hasher for small keys used in puzzles.
It should not be used in cryptographic or sensitive contexts and is vulnerable to HashDoS
attacks.
Integer writes smaller than 64 bits are packed into a pending u64, so a key such as
(u32, u16, u16) hashes like the manually packed value (a << 32) | (b << 16) | c.
The mixing step is inspired by wyhash. It uses XOR
to mix the current state and value, then does a 128bit multiplication with a large constant,
before XOR-ing the high and low 64bit halves.
The branches should be optimized out for fixed-sized types in release builds.
Example x86 assembly for u64:
movabsq $SEED,%rax
xorq %rdi,%rax
movabsq $MUL,%rcx
mulq %rcx
xorq %rdx,%rax
retqExample x86 assembly for (u32, u16, u16), showing bit packing followed by the same fold:
shlq $32,%rdi
shll $16,%esi
leaq (%rsi,%rdi),%rax
movzwl %dx,%ecx
orq %rax,%rcx
movabsq $SEED,%rax
xorq %rcx,%rax
movabsq $MUL,%rcx
mulq %rcx
xorq %rdx,%rax
retqTrait Implementations§
Source§impl Clone for FastHasher
impl Clone for FastHasher
Source§fn clone(&self) -> FastHasher
fn clone(&self) -> FastHasher
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FastHasher
impl Debug for FastHasher
Source§impl Default for FastHasher
impl Default for FastHasher
Source§impl Hasher for FastHasher
impl Hasher for FastHasher
Source§fn write_u128(&mut self, n: u128)
fn write_u128(&mut self, n: u128)
u128 into this hasher.Source§fn write_usize(&mut self, n: usize)
fn write_usize(&mut self, n: usize)
usize into this hasher.1.26.0 · Source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
i128 into this hasher.1.3.0 · Source§fn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
isize into this hasher.Source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
hasher_prefixfree_extras)