Closed
Description
We currently use FxHash
as the default hash function, but this function handles aligned values poorly: when hashing an integer, if the low X bits of the input value are 0 then the low X bits of the hash value will also be 0.
One option would be to copy Google's CityHash (used by SwissTable). This uses a long multiple and XORs the top and bottom words of the result together:
impl FxHasher {
#[inline]
#[cfg(target_pointer_width = "32")]
fn add_to_hash(&mut self, i: usize) {
let tmp = self.hash.wrapping_add(i) as u64 * 0xcc9e2d51;
self.hash = (tmp >> 32 ^ tmp) as usize;
}
#[inline]
#[cfg(target_pointer_width = "64")]
fn add_to_hash(&mut self, i: usize) {
let tmp = self.hash.wrapping_add(i) as u128 * 0x9ddfea08eb382d69;
self.hash = (tmp >> 64 ^ tmp) as usize;
}
}
Metadata
Metadata
Assignees
Labels
No labels