use std::collections::HashMap;
use std::hash::{BuildHasher, Hasher};
const K: u64 = 0x517cc1b727220a95;
pub(crate) struct FxHasher(u64);
impl Default for FxHasher {
#[inline]
fn default() -> Self {
FxHasher(0)
}
}
impl Hasher for FxHasher {
#[inline]
fn write(&mut self, bytes: &[u8]) {
for &b in bytes {
self.0 = (self.0.rotate_left(5) ^ b as u64).wrapping_mul(K);
}
}
#[inline]
fn write_u8(&mut self, i: u8) {
self.0 = (self.0.rotate_left(5) ^ i as u64).wrapping_mul(K);
}
#[inline]
fn write_u32(&mut self, i: u32) {
self.0 = (self.0.rotate_left(5) ^ i as u64).wrapping_mul(K);
}
#[inline]
fn write_u64(&mut self, i: u64) {
self.0 = (self.0.rotate_left(5) ^ i).wrapping_mul(K);
}
#[inline]
fn write_usize(&mut self, i: usize) {
self.0 = (self.0.rotate_left(5) ^ i as u64).wrapping_mul(K);
}
#[inline]
fn finish(&self) -> u64 {
self.0
}
}
#[derive(Clone, Default)]
pub(crate) struct FxBuildHasher;
impl BuildHasher for FxBuildHasher {
type Hasher = FxHasher;
#[inline]
fn build_hasher(&self) -> FxHasher {
FxHasher::default()
}
}
pub(crate) type FxHashMap<K, V> = HashMap<K, V, FxBuildHasher>;
pub(crate) type FxIndexMap<K, V> = indexmap::IndexMap<K, V, FxBuildHasher>;