use std::hash::DefaultHasher;
use std::hash::Hash;
use std::hash::Hasher;
pub type IndexMap<K, V> = indexmap::IndexMap<K, V, ahash::RandomState>;
pub type IndexSet<T> = indexmap::IndexSet<T, ahash::RandomState>;
pub type HashMap<K, V> = std::collections::HashMap<K, V, ahash::RandomState>;
pub type HashSet<T> = std::collections::HashSet<T, ahash::RandomState>;
pub(crate) fn eq_unique_by_name<T: PartialEq>(
a: &[crate::Node<T>],
b: &[crate::Node<T>],
get_name: impl Fn(&T) -> &crate::Name,
) -> bool {
if a.len() != b.len() {
return false;
}
a.iter().all(|item_a| {
let name = get_name(item_a);
b.iter()
.filter(|item_b| get_name(item_b) == name)
.any(|item_b| item_a == item_b)
})
}
pub(crate) fn hash_unordered<H: Hasher, T: Hash>(
items: impl Iterator<Item = T>,
state: &mut H,
len: usize,
) {
len.hash(state);
let mut combined = 0u64;
for item in items {
let mut h = DefaultHasher::new();
item.hash(&mut h);
combined ^= h.finish();
}
combined.hash(state);
}