1010import org .elasticsearch .common .util .BigArrays ;
1111import org .elasticsearch .common .util .BinarySearcher ;
1212import org .elasticsearch .common .util .LongArray ;
13- import org .elasticsearch .common .util .LongHash ;
1413import org .elasticsearch .core .Releasable ;
1514import org .elasticsearch .core .Releasables ;
1615import org .elasticsearch .search .sort .BucketedSort ;
@@ -28,30 +27,15 @@ public class LongTopNUniqueSort implements Releasable {
2827
2928 private final LongArray values ;
3029 private final LongBinarySearcher searcher ;
31- /**
32- * Hash holding the unique seen values.
33- * Adding is an O(1) operation to check if the new value is already in the top, and avoid trying to add it again, which is O(log(n)).
34- */
35- private final LongHash seenUniqueValues ;
3630
3731 private int count ;
3832
3933 public LongTopNUniqueSort (BigArrays bigArrays , SortOrder order , int limit ) {
4034 this .order = order ;
4135 this .limit = limit ;
4236 this .count = 0 ;
43-
44- boolean success = false ;
45- try {
46- this .values = bigArrays .newLongArray (limit , false );
47- this .seenUniqueValues = new LongHash (1 , bigArrays );
48- this .searcher = new LongBinarySearcher (values , order );
49- success = true ;
50- } finally {
51- if (success == false ) {
52- close ();
53- }
54- }
37+ this .values = bigArrays .newLongArray (limit , false );
38+ this .searcher = new LongBinarySearcher (values , order );
5539 }
5640
5741 public boolean collect (long value ) {
@@ -65,10 +49,6 @@ public boolean collect(long value) {
6549 return false ;
6650 }
6751
68- if (seenUniqueValues .add (value ) < 0 ) {
69- return true ;
70- }
71-
7252 if (count == 0 ) {
7353 values .set (0 , value );
7454 count ++;
@@ -179,6 +159,6 @@ private boolean betterThan(long lhs, long rhs) {
179159
180160 @ Override
181161 public final void close () {
182- Releasables .close (values , seenUniqueValues );
162+ Releasables .close (values );
183163 }
184164}
0 commit comments