Skip to content

Commit 3116bcc

Browse files
committed
fix: when advancing past the begin/end of a range container's iter, consume the whole thing
Before, the iterator would be left alone, rather than consumed when calling `advance_to`/`advance_back_to` past all values in the container.
1 parent d9c476b commit 3116bcc

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

roaring/src/bitmap/store/interval_store.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ impl<I: SliceIterator<Interval>> RunIter<I> {
712712
}
713713
Err(index) => {
714714
if index == self.intervals.as_slice().len() {
715+
// Consume the whole iterator
716+
self.intervals.nth(index);
715717
return;
716718
}
717719
if let Some(value) = index.checked_sub(1) {
@@ -747,6 +749,8 @@ impl<I: SliceIterator<Interval>> RunIter<I> {
747749
}
748750
Err(index) => {
749751
if index == 0 {
752+
// Consume the whole iterator
753+
self.intervals.nth_back(self.intervals.as_slice().len());
750754
return;
751755
}
752756
let backward_index = self.intervals.as_slice().len() - index;

roaring/tests/iter_advance_to.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,21 @@ fn advance_bitset_back_to_start_word() {
206206
}
207207
assert_eq!(iter.next(), None);
208208
}
209+
210+
#[test]
211+
fn advance_run_past_the_end() {
212+
let mut bitmap = RoaringBitmap::new();
213+
bitmap.insert_range(0..=0x35B00);
214+
let mut iter = bitmap.iter();
215+
iter.advance_to(0x35B01);
216+
assert_eq!(iter.next(), None);
217+
}
218+
219+
#[test]
220+
fn advance_run_back_before_start() {
221+
let mut bitmap = RoaringBitmap::new();
222+
bitmap.insert_range(500..=0x35B00);
223+
let mut iter = bitmap.iter();
224+
iter.advance_back_to(499);
225+
assert_eq!(iter.next_back(), None);
226+
}

0 commit comments

Comments
 (0)