pub mod list;
pub mod map;
use crate::lookup::store::{self, Positions, Retriever};
use std::ops::Index;
pub use crate::collections::list::rw::LkupVec;
pub use crate::collections::map::rw::LkupHashMap;
pub struct View<R, I> {
view: store::View<R>,
items: I,
}
impl<R, I> View<R, I> {
pub const fn new(view: store::View<R>, items: I) -> Self {
Self { view, items }
}
pub fn contains_key<Q>(&self, key: Q) -> bool
where
R: Retriever<Q>,
{
self.view.key_exist(key)
}
pub fn get_by_key<'a, Q>(&'a self, key: Q) -> impl Iterator<Item = &'a I::Output>
where
I: Index<&'a R::Pos>,
R: Retriever<Q>,
Q: 'a,
{
self.view.pos_by_key(key).iter().map(|p| &self.items[p])
}
pub fn get_by_many_keys<'a, It, Q>(&'a self, keys: It) -> impl Iterator<Item = &'a I::Output>
where
It: IntoIterator<Item = Q> + 'a,
I: Index<&'a R::Pos>,
R: Retriever<Q>,
Q: 'a,
{
self.view.pos_by_many_keys(keys).map(|p| &self.items[p])
}
pub fn items<'a>(&'a self) -> impl Iterator<Item = &'a I::Output>
where
I: Index<&'a R::Pos>,
R: Positions,
{
self.view.positions().map(|p| &self.items[p])
}
}
impl<L, I> std::ops::Deref for View<L, I>
where
L: std::ops::Deref,
{
type Target = L::Target;
fn deref(&self) -> &Self::Target {
self.view.deref()
}
}