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

bugfix: Treemap.andnot would not include items with no container on rhs #126

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions croaring/src/treemap/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,9 +938,18 @@ impl Treemap {
let mut treemap = Treemap::new();

for (key, bitmap) in &self.map {
if let Some(other_bitmap) = other.map.get(key) {
treemap.map.insert(*key, bitmap.andnot(other_bitmap));
}
let sub_bitmap = match other.map.get(key) {
Some(other_bitmap) => {
let sub_bitmap = bitmap.andnot(other_bitmap);
if sub_bitmap.is_empty() {
continue;
}
sub_bitmap
}
// x.andnot(empty) == x
None => bitmap.clone(),
};
treemap.map.insert(*key, sub_bitmap);
}

treemap
Expand Down
2 changes: 1 addition & 1 deletion croaring/src/treemap/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl<'a, 'b> Sub<&'a Treemap> for &'b Treemap {
/// let mut treemap2 = Treemap::new();
///
/// treemap2.add(25);
/// treemap1.add(u64::MAX);
/// treemap2.add(u64::MAX);
///
/// let treemap3 = &treemap1 - &treemap2;
///
Expand Down
12 changes: 12 additions & 0 deletions croaring/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ fn test_treemap_deserialize_jvm() {
}
}

#[test]
fn test_treemap_max_andnot_empty() {
let single_max = Treemap::of(&[std::u64::MAX]);
let empty = Treemap::new();
let diff = single_max.andnot(&empty);
assert_eq!(diff, single_max);

let mut diff = single_max.clone();
diff.andnot_inplace(&empty);
assert_eq!(diff, single_max);
}

#[test]
fn treemap_run_optimized() {
let mut initial = Bitmap::new();
Expand Down
Loading