-
Notifications
You must be signed in to change notification settings - Fork 84
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
Constant time len #182
base: main
Are you sure you want to change the base?
Constant time len #182
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,16 +17,16 @@ pub struct IntoIter { | |
} | ||
|
||
impl Iter<'_> { | ||
fn new(containers: &[Container]) -> Iter { | ||
let size_hint = containers.iter().map(|c| c.len()).sum(); | ||
Iter { inner: containers.iter().flatten(), size_hint } | ||
fn new(bitmap: &RoaringBitmap) -> Iter { | ||
let size_hint = bitmap.len(); | ||
Iter { inner: bitmap.containers.iter().flatten(), size_hint } | ||
Comment on lines
+20
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain to me the fact #179 removes the size_hint implementation and here we continue to track the length of the bitmap? I feel lost. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #176 Has the reasoning
We track the len of the |
||
} | ||
} | ||
|
||
impl IntoIter { | ||
fn new(containers: Vec<Container>) -> IntoIter { | ||
let size_hint = containers.iter().map(|c| c.len()).sum(); | ||
IntoIter { inner: containers.into_iter().flatten(), size_hint } | ||
fn new(bitmap: RoaringBitmap) -> IntoIter { | ||
let size_hint = bitmap.len(); | ||
IntoIter { inner: bitmap.containers.into_iter().flatten(), size_hint } | ||
} | ||
} | ||
|
||
|
@@ -95,7 +95,7 @@ impl RoaringBitmap { | |
/// assert_eq!(iter.next(), None); | ||
/// ``` | ||
pub fn iter(&self) -> Iter { | ||
Iter::new(&self.containers) | ||
Iter::new(self) | ||
} | ||
} | ||
|
||
|
@@ -113,7 +113,7 @@ impl IntoIterator for RoaringBitmap { | |
type IntoIter = IntoIter; | ||
|
||
fn into_iter(self) -> IntoIter { | ||
IntoIter::new(self.containers) | ||
IntoIter::new(self) | ||
} | ||
} | ||
|
||
|
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.
This is incorrect. Should have been return len if len > max
Computing max is not constant time for
BitmapStore