use std::hash::{BuildHasher, Hash, Hasher};
#[derive(Clone, Default, Debug)]
pub struct Hashing(foldhash::fast::FixedState);
impl BuildHasher for Hashing {
type Hasher = foldhash::fast::FoldHasher<'static>;
#[inline(always)]
fn build_hasher(&self) -> Self::Hasher { self.0.build_hasher() }
#[inline(always)]
fn hash_one<T: Hash>(&self, x: T) -> u64 {
let mut h = self.build_hasher();
x.hash(&mut h);
h.finish()
}
}
pub type HashMap<K, V> = hashbrown::HashMap<K, V, Hashing>;
pub type HashSet<K> = hashbrown::HashSet<K, Hashing>;
pub trait HashMapExt {
fn new() -> Self;
fn with_capacity(capacity: usize) -> Self;
}
impl<K, V> HashMapExt for HashMap<K, V> {
fn new() -> Self { Self::with_hasher(Hashing::default()) }
fn with_capacity(capacity: usize) -> Self { Self::with_capacity_and_hasher(capacity, Hashing::default()) }
}
pub trait HashSetExt {
fn new() -> Self;
fn with_capacity(capacity: usize) -> Self;
}
impl<K> HashSetExt for HashSet<K> {
fn new() -> Self { Self::with_hasher(Hashing::default()) }
fn with_capacity(capacity: usize) -> Self { Self::with_capacity_and_hasher(capacity, Hashing::default()) }
}