Skip to content

Commit cf73651

Browse files
authored
Use standard bit set impl in cardinality (#61816)
This replaces a specialized bit set implementation used in cardinality with our standard `BitArray` which works exactly the same way. Its also tracked by `BigArrays` which is great!
1 parent 77488ea commit cf73651

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
package org.elasticsearch.search.aggregations.metrics;
2121

2222
import org.apache.lucene.util.BytesRef;
23-
import org.apache.lucene.util.LongBitSet;
2423
import org.apache.lucene.util.packed.PackedInts;
2524
import org.elasticsearch.common.io.stream.StreamInput;
2625
import org.elasticsearch.common.io.stream.StreamOutput;
2726
import org.elasticsearch.common.lease.Releasable;
2827
import org.elasticsearch.common.lease.Releasables;
2928
import org.elasticsearch.common.util.BigArrays;
29+
import org.elasticsearch.common.util.BitArray;
3030
import org.elasticsearch.common.util.ByteArray;
3131
import org.elasticsearch.common.util.ByteUtils;
3232
import org.elasticsearch.common.util.IntArray;
@@ -63,7 +63,7 @@ public final class HyperLogLogPlusPlus implements Releasable {
6363
private static final boolean HYPERLOGLOG = true;
6464
public static final int DEFAULT_PRECISION = 14;
6565

66-
private final OpenBitSet algorithm;
66+
private final BitArray algorithm;
6767
private final HyperLogLog hll;
6868
private final LinearCounting lc;
6969

@@ -89,7 +89,7 @@ public static long memoryUsage(int precision) {
8989
public HyperLogLogPlusPlus(int precision, BigArrays bigArrays, long initialBucketCount) {
9090
hll = new HyperLogLog(bigArrays, initialBucketCount, precision);
9191
lc = new LinearCounting(bigArrays, initialBucketCount, precision, hll);
92-
algorithm = new OpenBitSet();
92+
algorithm = new BitArray(1, bigArrays);
9393
}
9494

9595
public int precision() {
@@ -181,7 +181,7 @@ void upgradeToHll(long bucket) {
181181

182182
@Override
183183
public void close() {
184-
Releasables.close(hll, lc);
184+
Releasables.close(algorithm, hll, lc);
185185
}
186186

187187
private Object getComparableData(long bucket) {
@@ -485,31 +485,4 @@ public int value() {
485485
return value;
486486
}
487487
}
488-
489-
/** looks and smells like the old openbitset. */
490-
static class OpenBitSet {
491-
LongBitSet impl = new LongBitSet(64);
492-
493-
boolean get(long bit) {
494-
if (bit < impl.length()) {
495-
return impl.get(bit);
496-
} else {
497-
return false;
498-
}
499-
}
500-
501-
void ensureCapacity(long bit) {
502-
impl = LongBitSet.ensureCapacity(impl, bit);
503-
}
504-
505-
void set(long bit) {
506-
ensureCapacity(bit);
507-
impl.set(bit);
508-
}
509-
510-
void clear(long bit) {
511-
ensureCapacity(bit);
512-
impl.clear(bit);
513-
}
514-
}
515488
}

0 commit comments

Comments
 (0)