use std::borrow::Borrow;
#[derive(Debug)]
pub struct CanonicalMap<'view, 'buffer, K, V> {
view: &'view buffa::MapView<'buffer, K, V>,
}
impl<'view, 'buffer, K, V> CanonicalMap<'view, 'buffer, K, V>
where
K: PartialEq,
{
#[must_use]
pub const fn from_view(view: &'view buffa::MapView<'buffer, K, V>) -> Self {
Self { view }
}
#[must_use]
pub fn len(&self) -> usize {
self.view.len_unique()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.view.is_empty()
}
#[must_use]
pub fn get<Q>(&self, key: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: PartialEq + ?Sized,
{
self.view.get(key)
}
#[must_use]
pub fn contains_key<Q>(&self, key: &Q) -> bool
where
K: Borrow<Q>,
Q: PartialEq + ?Sized,
{
self.view.contains_key(key)
}
pub fn keys(&self) -> impl Iterator<Item = &K> {
self.view.iter_unique().map(|(key, _)| key)
}
pub fn iter(&self) -> impl Iterator<Item = &(K, V)> {
self.view.iter_unique()
}
}