-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement SkipTo for iter::Iter #287
Closed
Closed
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6d11209
Implement SkipTo for iter::Iter
grelner df0b3cd
Fix panic when calling skip_to on iterator from empty bitmap
grelner c7f02c6
Make it compile on rust 1.66
grelner e8c57e0
Fix clippy warnings
grelner bb2a249
Implement advance_to and iter_from
grelner 025d489
Merge in workspace pr
grelner d25a8fe
Fix advance_to when coming from an iterator with an iter_back
grelner d3f9cdb
Make it compile on 1.66
grelner 2699703
Remove Empty variant in bitmap::store::Iter
grelner 65b5330
Revert change in imports
grelner 9a325bc
Refactor iterators
grelner feca297
Fix performance regression in iterators
grelner de80748
Remove dangling comment
grelner 32a3695
Simplify store::Iter::peek
grelner 522e945
Fix size_hint() when using advance_to
grelner 3c86fd9
Fix nightly clippy errors
grelner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use roaring::{RoaringBitmap, SkipTo}; | ||
|
||
#[test] | ||
fn basic() { | ||
let bm = RoaringBitmap::from([1,2,3,4,11,12,13,14]); | ||
let mut i = bm.iter().skip_to(10); | ||
for n in 11..=14 { | ||
assert_eq!(i.next(), Some(n)) | ||
} | ||
assert_eq!(i.next(), None); | ||
|
||
} | ||
|
||
#[test] | ||
fn empty() { | ||
let bm = RoaringBitmap::new(); | ||
assert_eq!(bm.iter().skip_to(31337).next(), None) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: using the full unmodified
self.containers
means this might skip backwards.To do this optimally, we might need to somewhat re-implement
std::iter::Flatten
so we can access theslice::Iter
directly (from which we can get the remaining slice), and access to the current container iterator. :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? self.containers is just a reference to RoaringBitmap.containers. It was added in this PR
edit: ah, self.containers is RoaringBitmap.containers here. Then there's something I don't understand here if they can be backwards 😅
I thought about changing iter::Iter to only contain a reference to containers, an index, and the iterator for the current container, and do the flatten part in ::next(), which I guess is what you're saying. This would also allow the SkipTo iterator to go backwards.
Still, are all these changes worth it to have a double ended iterator and cover the kinda weird case of skip_to to a point the iterator has already passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @grelner 👋
Sorry for the late reply, I'm in vacation 🌞
I agree with what @Dr-Emann explains here. This is, to me, the best way to implement this iterator.
Flatten
is not hard to implement. We can have a specialFlatten
type with all the originalFlatten
type logic but dedicated to slices and bitmaps so that it can skip groups according to thesplit
high group (skipping whole slices or bitmaps if the number we want to find is not in this group).Let's forget about the
SkipTo
wrapper and only implement a non-lazy method likeIterator::advance_by
method that directly advances the iterator to the requested number. This method,skip_to
, is only available on thebitmap::Iter/IntoIter
types, so there is no need to think aboutstd::iter::Rev
iterator adaptator.