Skip to content

Commit

Permalink
Correctly set bits to 0 when merge overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
mkavanagh committed Aug 7, 2020
1 parent 142cd38 commit 126be11
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ public void add(int value) {
bitmap = bitmaps[i] = new RoaringBitmap();
}

if (!bitmap.contains(value)) {
if (!bitmap.checkedRemove(value)) {
bitmap.add(value);
return;
}

bitmap.remove(value);
}

// If we reach this point, the frequency of this value is >= 2^(bitmaps.length)
Expand Down Expand Up @@ -234,7 +232,7 @@ public BitmapFrequencyCounter merge(BitmapFrequencyCounter other) {
int freq = 1 << bitmaps.length;

for (int k = 0; k < bitmaps.length; k++) {
if (bitmaps[j].contains(value)) {
if (bitmaps[k].checkedRemove(value)) {
freq += 1 << k;
}
}
Expand Down

0 comments on commit 126be11

Please sign in to comment.