use super::DocId;
pub type Position = u32;
pub trait TermStore {
type List<'a>: PostingList
where
Self: 'a;
fn get(&self, term: &str) -> Option<Self::List<'_>>;
fn term_count(&self) -> usize;
fn memory_bytes(&self) -> usize;
}
pub trait PostingList {
type Cursor<'a>: PostingCursor
where
Self: 'a;
fn doc_freq(&self) -> u32;
fn cursor(&self) -> Self::Cursor<'_>;
}
pub trait PostingCursor {
fn doc(&self) -> Option<DocId>;
fn advance(&mut self) -> Option<DocId>;
fn seek(&mut self, target: DocId) -> Option<DocId>;
fn positions(&mut self) -> &[Position];
fn term_freq(&mut self) -> u32 {
self.positions().len() as u32
}
}
impl<T: PostingList + ?Sized> PostingList for &T {
type Cursor<'a>
= T::Cursor<'a>
where
Self: 'a;
fn doc_freq(&self) -> u32 {
(**self).doc_freq()
}
fn cursor(&self) -> Self::Cursor<'_> {
(**self).cursor()
}
}