From 3d23dcd74291240858148ea21e0d1bbb9667045c Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 3 Sep 2020 12:37:30 -0400 Subject: [PATCH] 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! --- .../metrics/HyperLogLogPlusPlus.java | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java index 76dcb1b5aee..77c9391b313 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/HyperLogLogPlusPlus.java @@ -20,13 +20,13 @@ package org.elasticsearch.search.aggregations.metrics; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.LongBitSet; import org.apache.lucene.util.packed.PackedInts; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.ByteArray; import org.elasticsearch.common.util.ByteUtils; import org.elasticsearch.common.util.IntArray; @@ -63,7 +63,7 @@ public final class HyperLogLogPlusPlus implements Releasable { private static final boolean HYPERLOGLOG = true; public static final int DEFAULT_PRECISION = 14; - private final OpenBitSet algorithm; + private final BitArray algorithm; private final HyperLogLog hll; private final LinearCounting lc; @@ -89,7 +89,7 @@ public final class HyperLogLogPlusPlus implements Releasable { public HyperLogLogPlusPlus(int precision, BigArrays bigArrays, long initialBucketCount) { hll = new HyperLogLog(bigArrays, initialBucketCount, precision); lc = new LinearCounting(bigArrays, initialBucketCount, precision, hll); - algorithm = new OpenBitSet(); + algorithm = new BitArray(1, bigArrays); } public int precision() { @@ -181,7 +181,7 @@ public final class HyperLogLogPlusPlus implements Releasable { @Override public void close() { - Releasables.close(hll, lc); + Releasables.close(algorithm, hll, lc); } private Object getComparableData(long bucket) { @@ -485,31 +485,4 @@ public final class HyperLogLogPlusPlus implements Releasable { 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); - } - } }