use foldhash::fast::FixedState;
use std::hash::{BuildHasher, Hash, Hasher};
pub fn hash_set<S: IntoIterator, H: Hasher>(set: S, hasher: &mut H)
where
S::Item: Hash,
{
let inner = FixedState::default();
let mut hash = 0u64;
for item in set {
hash = hash.wrapping_add(inner.hash_one(item));
}
hasher.write_u64(hash);
}
pub fn hash_set_opt<S: IntoIterator, H: Hasher>(set_opt: Option<S>, hasher: &mut H)
where
S::Item: Hash,
{
if let Some(set) = set_opt {
hash_set(set, hasher);
}
}
pub fn hash_map<'a, K: 'a + Hash, V: 'a + Hash, H: Hasher>(map: impl 'a + IntoIterator<Item = (&'a K, &'a V)>, hasher: &mut H) {
let inner = FixedState::default();
let mut hash = 0u64;
for entry in map {
hash = hash.wrapping_add(inner.hash_one(entry));
}
hasher.write_u64(hash);
}