java.lang.Object
org.elasticsearch.compute.data.sort.LongTopNSet
All Implemented Interfaces:
Closeable, AutoCloseable, org.elasticsearch.core.Releasable

public class LongTopNSet extends Object implements org.elasticsearch.core.Releasable
Aggregates the top N collected values, and keeps them sorted.

Collection is O(1) for values out of the current top N. For values better than the worst value, it's O(log(n)).

  • Constructor Details

  • Method Details

    • collect

      public boolean collect(long value)
      Adds the value to the top N, as long as it is "better" than the worst value, or the top isn't full yet.
    • reduceLimitByOne

      public void reduceLimitByOne()
      Reduces the limit of the top N by 1.

      This method is specifically used to count for the null value, and ignore the extra element here without extra cost.

    • getWorstValue

      public long getWorstValue()
      Returns the worst value in the top.

      The worst is the greatest value for SortOrder.ASC, and the lowest value for SortOrder.DESC.

    • getOrder

      public SortOrder getOrder()
      The order of the sort.
    • getLimit

      public int getLimit()
    • getCount

      public int getCount()
    • close

      public final void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface org.elasticsearch.core.Releasable