Skip to content

Commit

Permalink
Merge pull request #281 from RoaringBitmap/intersection-with-serialized
Browse files Browse the repository at this point in the history
Direct intersections with serialized RoaringBitmaps
  • Loading branch information
Kerollmops authored Jun 8, 2024
2 parents 2288f7c + 457b2c9 commit 6391a97
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/bitmap/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ impl Container {
self.store.len()
}

pub fn is_empty(&self) -> bool {
self.store.is_empty()
}

pub fn insert(&mut self, index: u16) -> bool {
if self.store.insert(index) {
self.ensure_correct_store();
Expand Down
4 changes: 2 additions & 2 deletions src/bitmap/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl RoaringBitmap {
match self.containers.binary_search_by_key(&key, |c| c.key) {
Ok(loc) => {
if self.containers[loc].remove(index) {
if self.containers[loc].len() == 0 {
if self.containers[loc].is_empty() {
self.containers.remove(loc);
}
true
Expand Down Expand Up @@ -253,7 +253,7 @@ impl RoaringBitmap {
let a = if key == start_container_key { start_index } else { 0 };
let b = if key == end_container_key { end_index } else { u16::MAX };
removed += self.containers[index].remove_range(a..=b);
if self.containers[index].len() == 0 {
if self.containers[index].is_empty() {
self.containers.remove(index);
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/bitmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ mod cmp;
mod inherent;
mod iter;
mod ops;
#[cfg(feature = "std")]
mod ops_with_serialized;
#[cfg(feature = "serde")]
mod serde;
#[cfg(feature = "std")]
mod serialization;
pub(crate) mod serialization;

use self::cmp::Pairs;
pub use self::iter::IntoIter;
Expand Down
4 changes: 2 additions & 2 deletions src/bitmap/multiops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fn try_multi_or_owned<E>(
}

containers.retain_mut(|container| {
if container.len() > 0 {
if !container.is_empty() {
container.ensure_correct_store();
true
} else {
Expand All @@ -258,7 +258,7 @@ fn try_multi_xor_owned<E>(
}

containers.retain_mut(|container| {
if container.len() > 0 {
if !container.is_empty() {
container.ensure_correct_store();
true
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/bitmap/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl BitAnd<&RoaringBitmap> for &RoaringBitmap {
for pair in Pairs::new(&self.containers, &rhs.containers) {
if let (Some(lhs), Some(rhs)) = pair {
let container = BitAnd::bitand(lhs, rhs);
if container.len() != 0 {
if !container.is_empty() {
containers.push(container);
}
}
Expand All @@ -248,7 +248,7 @@ impl BitAndAssign<RoaringBitmap> for RoaringBitmap {
let rhs_cont = &mut rhs.containers[loc];
let rhs_cont = mem::replace(rhs_cont, Container::new(rhs_cont.key));
BitAndAssign::bitand_assign(cont, rhs_cont);
cont.len() != 0
!cont.is_empty()
}
Err(_) => false,
}
Expand All @@ -264,7 +264,7 @@ impl BitAndAssign<&RoaringBitmap> for RoaringBitmap {
match rhs.containers.binary_search_by_key(&key, |c| c.key) {
Ok(loc) => {
BitAndAssign::bitand_assign(cont, &rhs.containers[loc]);
cont.len() != 0
!cont.is_empty()
}
Err(_) => false,
}
Expand Down Expand Up @@ -314,7 +314,7 @@ impl Sub<&RoaringBitmap> for &RoaringBitmap {
(None, Some(_)) => (),
(Some(lhs), Some(rhs)) => {
let container = Sub::sub(lhs, rhs);
if container.len() != 0 {
if !container.is_empty() {
containers.push(container);
}
}
Expand All @@ -340,7 +340,7 @@ impl SubAssign<&RoaringBitmap> for RoaringBitmap {
match rhs.containers.binary_search_by_key(&cont.key, |c| c.key) {
Ok(loc) => {
SubAssign::sub_assign(cont, &rhs.containers[loc]);
cont.len() != 0
!cont.is_empty()
}
Err(_) => true,
}
Expand Down Expand Up @@ -390,7 +390,7 @@ impl BitXor<&RoaringBitmap> for &RoaringBitmap {
(None, Some(rhs)) => containers.push(rhs.clone()),
(Some(lhs), Some(rhs)) => {
let container = BitXor::bitxor(lhs, rhs);
if container.len() != 0 {
if !container.is_empty() {
containers.push(container);
}
}
Expand All @@ -409,7 +409,7 @@ impl BitXorAssign<RoaringBitmap> for RoaringBitmap {
match pair {
(Some(mut lhs), Some(rhs)) => {
BitXorAssign::bitxor_assign(&mut lhs, rhs);
if lhs.len() != 0 {
if !lhs.is_empty() {
self.containers.push(lhs);
}
}
Expand All @@ -428,7 +428,7 @@ impl BitXorAssign<&RoaringBitmap> for RoaringBitmap {
match pair {
(Some(mut lhs), Some(rhs)) => {
BitXorAssign::bitxor_assign(&mut lhs, rhs);
if lhs.len() != 0 {
if !lhs.is_empty() {
self.containers.push(lhs);
}
}
Expand Down
Loading

0 comments on commit 6391a97

Please sign in to comment.