2020package org .elasticsearch .search .aggregations .metrics ;
2121
2222import org .apache .lucene .util .BytesRef ;
23- import org .apache .lucene .util .LongBitSet ;
2423import org .apache .lucene .util .packed .PackedInts ;
2524import org .elasticsearch .common .io .stream .StreamInput ;
2625import org .elasticsearch .common .io .stream .StreamOutput ;
2726import org .elasticsearch .common .lease .Releasable ;
2827import org .elasticsearch .common .lease .Releasables ;
2928import org .elasticsearch .common .util .BigArrays ;
29+ import org .elasticsearch .common .util .BitArray ;
3030import org .elasticsearch .common .util .ByteArray ;
3131import org .elasticsearch .common .util .ByteUtils ;
3232import 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