Skip to content

Commit

Permalink
bugfix: Treemap.andnot would not include items with no container on rhs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Emann committed Jan 13, 2024
1 parent b01b9ce commit e3d1754
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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
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

0 comments on commit e3d1754

Please sign in to comment.