Use standard bit set impl in cardinality (#61816) (#61930)

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!
This commit is contained in:
Nik Everett 2020-09-03 12:37:30 -04:00 committed by GitHub
parent 3934e14bc0
commit 3d23dcd742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 31 deletions

View File

@ -20,13 +20,13 @@
package org.elasticsearch.search.aggregations.metrics; package org.elasticsearch.search.aggregations.metrics;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LongBitSet;
import org.apache.lucene.util.packed.PackedInts; import org.apache.lucene.util.packed.PackedInts;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.BitArray;
import org.elasticsearch.common.util.ByteArray; import org.elasticsearch.common.util.ByteArray;
import org.elasticsearch.common.util.ByteUtils; import org.elasticsearch.common.util.ByteUtils;
import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.IntArray;
@ -63,7 +63,7 @@ public final class HyperLogLogPlusPlus implements Releasable {
private static final boolean HYPERLOGLOG = true; private static final boolean HYPERLOGLOG = true;
public static final int DEFAULT_PRECISION = 14; public static final int DEFAULT_PRECISION = 14;
private final OpenBitSet algorithm; private final BitArray algorithm;
private final HyperLogLog hll; private final HyperLogLog hll;
private final LinearCounting lc; private final LinearCounting lc;
@ -89,7 +89,7 @@ public final class HyperLogLogPlusPlus implements Releasable {
public HyperLogLogPlusPlus(int precision, BigArrays bigArrays, long initialBucketCount) { public HyperLogLogPlusPlus(int precision, BigArrays bigArrays, long initialBucketCount) {
hll = new HyperLogLog(bigArrays, initialBucketCount, precision); hll = new HyperLogLog(bigArrays, initialBucketCount, precision);
lc = new LinearCounting(bigArrays, initialBucketCount, precision, hll); lc = new LinearCounting(bigArrays, initialBucketCount, precision, hll);
algorithm = new OpenBitSet(); algorithm = new BitArray(1, bigArrays);
} }
public int precision() { public int precision() {
@ -181,7 +181,7 @@ public final class HyperLogLogPlusPlus implements Releasable {
@Override @Override
public void close() { public void close() {
Releasables.close(hll, lc); Releasables.close(algorithm, hll, lc);
} }
private Object getComparableData(long bucket) { private Object getComparableData(long bucket) {
@ -485,31 +485,4 @@ public final class HyperLogLogPlusPlus implements Releasable {
return value; return value;
} }
} }
/** looks and smells like the old openbitset. */
static class OpenBitSet {
LongBitSet impl = new LongBitSet(64);
boolean get(long bit) {
if (bit < impl.length()) {
return impl.get(bit);
} else {
return false;
}
}
void ensureCapacity(long bit) {
impl = LongBitSet.ensureCapacity(impl, bit);
}
void set(long bit) {
ensureCapacity(bit);
impl.set(bit);
}
void clear(long bit) {
ensureCapacity(bit);
impl.clear(bit);
}
}
} }