use roaring::{RoaringBitmap, bitmap::IntoIter}; use crate::DocumentId; use super::{DocIter, Distinct}; /// A distinct implementer that does not perform any distinct, /// and simply returns an iterator to the candidates. pub struct NoopDistinct; pub struct NoopDistinctIter { candidates: IntoIter, excluded: RoaringBitmap, } impl Iterator for NoopDistinctIter { type Item = anyhow::Result; fn next(&mut self) -> Option { self.candidates.next().map(Ok) } } impl DocIter for NoopDistinctIter { fn into_excluded(self) -> RoaringBitmap { self.excluded } } impl Distinct for NoopDistinct { type Iter = NoopDistinctIter; fn distinct(&mut self, candidates: RoaringBitmap, excluded: RoaringBitmap) -> Self::Iter { NoopDistinctIter { candidates: candidates.into_iter(), excluded, } } } #[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::>(), (1..10).collect::>() ); let excluded = iter.into_excluded(); assert!(excluded.is_empty()); } }