2021-04-14 12:00:45 +02:00
|
|
|
use roaring::{RoaringBitmap, bitmap::IntoIter};
|
2021-04-07 12:38:48 +02:00
|
|
|
|
2021-06-14 16:46:19 +02:00
|
|
|
use crate::{DocumentId, Result};
|
2021-04-07 12:38:48 +02:00
|
|
|
use super::{DocIter, Distinct};
|
|
|
|
|
2021-04-15 15:29:37 +02:00
|
|
|
/// A distinct implementer that does not perform any distinct,
|
|
|
|
/// and simply returns an iterator to the candidates.
|
2021-04-07 12:38:48 +02:00
|
|
|
pub struct NoopDistinct;
|
|
|
|
|
|
|
|
pub struct NoopDistinctIter {
|
2021-04-14 12:00:45 +02:00
|
|
|
candidates: IntoIter,
|
2021-04-07 12:38:48 +02:00
|
|
|
excluded: RoaringBitmap,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Iterator for NoopDistinctIter {
|
2021-06-14 16:46:19 +02:00
|
|
|
type Item = Result<DocumentId>;
|
2021-04-07 12:38:48 +02:00
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
2021-04-14 12:18:13 +02:00
|
|
|
self.candidates.next().map(Ok)
|
2021-04-07 12:38:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DocIter for NoopDistinctIter {
|
|
|
|
fn into_excluded(self) -> RoaringBitmap {
|
|
|
|
self.excluded
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 14:43:48 +02:00
|
|
|
impl Distinct for NoopDistinct {
|
2021-04-07 12:38:48 +02:00
|
|
|
type Iter = NoopDistinctIter;
|
|
|
|
|
|
|
|
fn distinct(&mut self, candidates: RoaringBitmap, excluded: RoaringBitmap) -> Self::Iter {
|
|
|
|
NoopDistinctIter {
|
|
|
|
candidates: candidates.into_iter(),
|
|
|
|
excluded,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-15 15:29:37 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_noop() {
|
|
|
|
let candidates = (1..10).collect();
|
|
|
|
let excluded = RoaringBitmap::new();
|
|
|
|
let mut iter = NoopDistinct.distinct(candidates, excluded);
|
|
|
|
assert_eq!(
|
|
|
|
iter.by_ref().map(Result::unwrap).collect::<Vec<_>>(),
|
|
|
|
(1..10).collect::<Vec<_>>()
|
|
|
|
);
|
|
|
|
|
|
|
|
let excluded = iter.into_excluded();
|
|
|
|
assert!(excluded.is_empty());
|
|
|
|
}
|
|
|
|
}
|