use super::HopscotchMap;
use core::fmt;
use core::hash::{BuildHasher, Hash};
impl<K: 'static, V: 'static, S: Default> Default for HopscotchMap<K, V, S> {
fn default() -> Self {
Self::with_hasher(S::default())
}
}
impl<K, V, S> fmt::Debug for HopscotchMap<K, V, S>
where
K: Eq + Clone + fmt::Debug + 'static,
V: Clone + fmt::Debug + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_map().entries(self.iter()).finish()
}
}
impl<K, V, S> Clone for HopscotchMap<K, V, S>
where
K: Hash + Eq + Clone + Send + 'static,
V: Clone + Send + 'static,
S: BuildHasher + Clone,
{
fn clone(&self) -> Self {
let cloned = Self::with_capacity_and_hasher(self.capacity(), self.hasher().clone());
for (k, v) in self.iter() {
cloned.insert(k, v);
}
cloned
}
}
impl<K, V, S> Extend<(K, V)> for HopscotchMap<K, V, S>
where
K: Hash + Eq + Clone + Send + 'static,
V: Clone + Send + 'static,
S: BuildHasher,
{
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I) {
HopscotchMap::extend(&*self, iter);
}
}
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HopscotchMap<K, V, S>
where
K: Hash + Eq + Copy + Send + 'static,
V: Copy + Send + 'static,
S: BuildHasher,
{
fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I) {
HopscotchMap::extend(&*self, iter.into_iter().map(|(k, v)| (*k, *v)));
}
}
impl<K, V, S> PartialEq for HopscotchMap<K, V, S>
where
K: Hash + Eq + Clone + Send + 'static,
V: Clone + PartialEq + Send + 'static,
S: BuildHasher,
{
fn eq(&self, other: &Self) -> bool {
self.len() == other.len()
&& self
.iter()
.all(|(k, v)| other.get(&k).is_some_and(|ov| ov == v))
}
}
impl<K, V, S> Eq for HopscotchMap<K, V, S>
where
K: Hash + Eq + Clone + Send + 'static,
V: Clone + Eq + Send + 'static,
S: BuildHasher,
{
}