Skip to content

Commit 820b270

Browse files
committed
lazily compute iterator len, add interator overrides
This means the price of visting every container is only paid when needed: e.g. when calling `.collect()` This adds more efficent overrides for `count`, `nth` and `nth_back`, and implements `FusedIterator`
1 parent c4e3b34 commit 820b270

File tree

5 files changed

+370
-46
lines changed

5 files changed

+370
-46
lines changed

roaring/src/bitmap/container.rs

+17
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,21 @@ impl Iterator for Iter<'_> {
300300
fn next(&mut self) -> Option<u32> {
301301
self.inner.next().map(|i| util::join(self.key, i))
302302
}
303+
304+
fn size_hint(&self) -> (usize, Option<usize>) {
305+
self.inner.size_hint()
306+
}
307+
308+
fn count(self) -> usize
309+
where
310+
Self: Sized,
311+
{
312+
self.inner.count()
313+
}
314+
315+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
316+
self.inner.nth(n).map(|i| util::join(self.key, i))
317+
}
303318
}
304319

305320
impl DoubleEndedIterator for Iter<'_> {
@@ -308,6 +323,8 @@ impl DoubleEndedIterator for Iter<'_> {
308323
}
309324
}
310325

326+
impl ExactSizeIterator for Iter<'_> {}
327+
311328
impl fmt::Debug for Container {
312329
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
313330
format!("Container<{:?} @ {:?}>", self.len(), self.key).fmt(formatter)

0 commit comments

Comments
 (0)