Skip to content

Commit

Permalink
Update the insert to push when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Sep 23, 2024
1 parent d8f1829 commit 1b32c1e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions roaring/src/bitmap/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,20 @@ impl RoaringBitmap {
/// ```
#[inline]
pub fn insert(&mut self, value: u32) -> bool {
let (key, index) = util::split(value);
let container = match self.containers.binary_search_by_key(&key, |c| c.key) {
Ok(loc) => &mut self.containers[loc],
Err(loc) => {
self.containers.insert(loc, Container::new(key));
&mut self.containers[loc]
}
};
container.insert(index)
if self.max().map_or(true, |max| value > max) {
self.push_unchecked(value);
true
} else {
let (key, index) = util::split(value);
let container = match self.containers.binary_search_by_key(&key, |c| c.key) {
Ok(loc) => &mut self.containers[loc],
Err(loc) => {
self.containers.insert(loc, Container::new(key));
&mut self.containers[loc]
}
};
container.insert(index)
}
}

/// Search for the specific container by the given key.
Expand Down

0 comments on commit 1b32c1e

Please sign in to comment.