Skip to content

Commit

Permalink
CountingBloom: counters can overflow #20
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmueller committed Dec 27, 2019
1 parent 9b6c6d8 commit 8620698
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public long getBitCount() {
entryCount = Math.max(1, entryCount);
this.k = k;
this.seed = Hash.randomSeed();
this.bits = (long) (4 * entryCount * bitsPerKey);
// if the entryCount is very small, then there is a relatively high
// probability that one of the counter overflows, so we add
// a fixed number of bits (64 in this case) to reduce the probability of this
// (this is a workaround only)
this.bits = (long) (4 * entryCount * bitsPerKey) + 64;
arraySize = (int) ((bits + 63) / 64);
counts = new long[arraySize];
}
Expand All @@ -53,6 +57,11 @@ public void add(long key) {
int b = (int) hash;
for (int i = 0; i < k; i++) {
int index = Hash.reduce(a, arraySize << 4);
int oldCount = (int) (counts[index >>> 4] >>> (index << 2)) & 0xf;
if (oldCount >= 15) {
// TODO we should also undo what was added so far
throw new UnsupportedOperationException("Counter overflow");
}
counts[index >>> 4] += getBit(index);
a += b;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public static GolombCompressedSet construct(long[] keys, int setting) {
return new GolombCompressedSet(keys, keys.length, setting);
}

// TODO rearrange Rice codes so that buckets have all variable parts first, then fixed part
// this is to speed up lookup with large bucket sizes

GolombCompressedSet(long[] keys, int len, int fingerprintBits) {
if (fingerprintBits < 4 || fingerprintBits > 50) {
throw new IllegalArgumentException();
Expand Down

0 comments on commit 8620698

Please sign in to comment.