pub mod ro;
pub mod rw;
use crate::index::{
indices::Indices,
store::{Filterable, MetaData},
view::{Filter, Keys, View},
Indexable,
};
#[repr(transparent)]
pub struct Retriever<'a, F, I>(Filter<'a, F, I>);
impl<'a, F, I> Retriever<'a, F, I>
where
F: Filterable,
{
pub const fn new(filter: &'a F, items: &'a I) -> Self {
Self(Filter::new(filter, items))
}
#[inline]
pub fn eq(&self, key: &F::Key) -> Indices<'a, F::Index>
where
F::Index: Clone,
{
self.0.eq(key)
}
#[inline]
pub fn contains(&self, key: &F::Key) -> bool {
self.0.filter.contains(key)
}
#[inline]
pub fn get(&self, key: &F::Key) -> impl Iterator<Item = &'a <I as Indexable<F::Index>>::Output>
where
I: Indexable<F::Index>,
{
self.0.items.items(self.0.filter.get(key).iter())
}
#[inline]
pub fn get_many<II>(
&self,
keys: II,
) -> impl Iterator<Item = &'a <I as Indexable<F::Index>>::Output>
where
II: IntoIterator<Item = F::Key> + 'a,
I: Indexable<F::Index>,
<I as Indexable<F::Index>>::Output: Sized,
{
self.0.filter.get_many(keys).items(self.0.items)
}
#[inline]
pub fn filter<P>(
&self,
predicate: P,
) -> impl Iterator<Item = &'a <I as Indexable<F::Index>>::Output>
where
P: Fn(&Filter<'a, F, I>) -> Indices<'a, F::Index>,
I: Indexable<F::Index>,
F::Index: Clone,
{
predicate(&self.0).items(self.0.items)
}
#[inline]
pub fn create_view<It>(&self, keys: It) -> View<'a, F, F, I>
where
It: IntoIterator<Item = <F as Keys>::Key>,
F: Keys<Key = <F as Filterable>::Key>,
I: Indexable<F::Index>,
{
View::new(F::from_iter(keys), self.0.filter, self.0.items)
}
#[inline]
pub fn meta(&self) -> F::Meta<'_>
where
F: MetaData,
{
self.0.filter.meta()
}
}