use core::hash::{BuildHasher, Hash};
use super::{Bucket, Entries, Equivalent, IndexMap};
pub trait MutableKeys: private::Sealed {
type Key;
type Value;
fn get_full_mut2<Q: ?Sized>(
&mut self,
key: &Q,
) -> Option<(usize, &mut Self::Key, &mut Self::Value)>
where
Q: Hash + Equivalent<Self::Key>;
fn get_index_mut2(&mut self, index: usize) -> Option<(&mut Self::Key, &mut Self::Value)>;
fn retain2<F>(&mut self, keep: F)
where
F: FnMut(&mut Self::Key, &mut Self::Value) -> bool;
}
impl<K, V, S> MutableKeys for IndexMap<K, V, S>
where
S: BuildHasher,
{
type Key = K;
type Value = V;
fn get_full_mut2<Q: ?Sized>(&mut self, key: &Q) -> Option<(usize, &mut K, &mut V)>
where
Q: Hash + Equivalent<K>,
{
if let Some(i) = self.get_index_of(key) {
let entry = &mut self.as_entries_mut()[i];
Some((i, &mut entry.key, &mut entry.value))
} else {
None
}
}
fn get_index_mut2(&mut self, index: usize) -> Option<(&mut K, &mut V)> {
self.as_entries_mut().get_mut(index).map(Bucket::muts)
}
fn retain2<F>(&mut self, keep: F)
where
F: FnMut(&mut K, &mut V) -> bool,
{
self.retain_mut(keep)
}
}
mod private {
pub trait Sealed {}
impl<K, V, S> Sealed for super::IndexMap<K, V, S> {}
}