Added impl Postings for Boxed and ref of postings.

This commit is contained in:
Paul Masurel
2016-06-24 14:50:58 +09:00
parent 053e9c7863
commit 0b682e2c9e
2 changed files with 49 additions and 3 deletions

View File

@@ -109,4 +109,4 @@ pub fn intersection<'a>(postings: Vec<SegmentPostings<'a>>) -> IntersectionPosti
})
.collect();
IntersectionPostings::new(boxed_postings)
}
}

View File

@@ -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<TPostings: Postings> Postings for Box<TPostings> {
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()
}
}