diff --git a/src/postings/intersection.rs b/src/postings/intersection.rs index b2a65c879..a281c5eee 100644 --- a/src/postings/intersection.rs +++ b/src/postings/intersection.rs @@ -109,4 +109,4 @@ pub fn intersection<'a>(postings: Vec>) -> IntersectionPosti }) .collect(); IntersectionPostings::new(boxed_postings) -} \ No newline at end of file +} diff --git a/src/postings/postings.rs b/src/postings/postings.rs index 486d84b63..eea5a7bbd 100644 --- a/src/postings/postings.rs +++ b/src/postings/postings.rs @@ -1,4 +1,6 @@ use DocId; +use std::borrow::Borrow; +use std::borrow::BorrowMut; #[derive(PartialEq, Eq, Debug)] pub enum SkipResult { @@ -12,13 +14,57 @@ pub trait Postings { // next needs to be called a first time to point to the correct element. fn next(&mut self,) -> bool; - fn doc(&self,) -> DocId; - // after skipping position // the iterator in such a way that doc() will return a // value greater or equal to target. fn skip_next(&mut self, target: DocId) -> SkipResult; + fn doc(&self,) -> DocId; + fn doc_freq(&self,) -> usize; } +impl Postings for Box { + fn next(&mut self,) -> bool { + let unboxed: &mut TPostings = self.borrow_mut(); + unboxed.next() + } + + fn skip_next(&mut self, target: DocId) -> SkipResult { + let unboxed: &mut TPostings = self.borrow_mut(); + unboxed.skip_next(target) + } + + fn doc(&self,) -> DocId { + let unboxed: &TPostings = self.borrow(); + unboxed.borrow().doc() + } + + fn doc_freq(&self,) -> usize { + let unboxed: &TPostings = self.borrow(); + unboxed.doc_freq() + } +} + +impl<'a, TPostings: Postings> Postings for &'a mut TPostings { + fn next(&mut self,) -> bool { + let unref: &mut TPostings = *self; + unref.next() + } + + fn skip_next(&mut self, target: DocId) -> SkipResult { + let unref: &mut TPostings = *self; + unref.skip_next(target) + } + + fn doc(&self,) -> DocId { + let unref: &TPostings = *self; + unref.doc() + } + + + fn doc_freq(&self,) -> usize { + let unref: &TPostings = *self; + unref.doc_freq() + } +}