COLLECTIONS-823: Modified ArrayCountingBloomFilter.forEachBitMap to be more efficient (#316)

* Modified forEachBitMap
* made blocksm1 final and initialized with counts.length
This commit is contained in:
Claude Warren 2022-07-05 13:36:02 +01:00 committed by GitHub
parent 20b0357048
commit fcbcb2e746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 1 deletions

View File

@ -231,7 +231,29 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
@Override
public boolean forEachBitMap(LongPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
return BitMapProducer.fromIndexProducer(this, shape.getNumberOfBits()).forEachBitMap(consumer);
final int blocksm1 = BitMap.numberOfBitMaps(counts.length) - 1;
int i = 0;
long value;
// must break final block separate as the number of bits may not fall on the long boundary
for (int j = 0; j < blocksm1; j++) {
value = 0;
for (int k = 0; k < Long.SIZE; k++) {
if (counts[i++] != 0) {
value |= BitMap.getLongBit(k);
}
}
if (!consumer.test(value)) {
return false;
}
}
// Final block
value = 0;
for (int k = 0; i < counts.length; k++) {
if (counts[i++] != 0) {
value |= BitMap.getLongBit(k);
}
}
return consumer.test(value);
}
/**