Skip to content
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

Direct intersections with serialized RoaringBitmaps #281

Merged
merged 12 commits into from
Jun 8, 2024
4 changes: 4 additions & 0 deletions src/bitmap/container.rs
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 2 additions & 2 deletions src/bitmap/inherent.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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;
}
4 changes: 3 additions & 1 deletion src/bitmap/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions src/bitmap/multiops.rs
Original file line number Diff line number Diff line change
@@ -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 {
@@ -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 {
16 changes: 8 additions & 8 deletions src/bitmap/ops.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
@@ -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,
}
@@ -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,
}
@@ -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);
}
}
@@ -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,
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
Loading