- All Implemented Interfaces:
Closeable,AutoCloseable,Releasable
BytesRef values, kept 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))
for the binary search plus O(n) for the shift on insertion (n is bounded by limit).
Backing storage is an array of BreakingBytesRefBuilder, one per slot, sized at most limit.
Each slot owns its bytes; on insertion, references are shifted right and the displaced (worst) slot is
reused as the destination for the new value.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleancollect(org.apache.lucene.util.BytesRef 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.intgetCount()intgetLimit()getOrder()The order of the sort.org.apache.lucene.util.BytesRefReturns a deep copy of the worst value in the top.org.apache.lucene.util.BytesRefReturns a non-owningBytesRefview of the worst value in the top.voidReduces the limit of the top N by 1.
-
Constructor Details
-
BytesRefTopNSet
-
-
Method Details
-
collect
public boolean collect(org.apache.lucene.util.BytesRef 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 org.apache.lucene.util.BytesRef getWorstValue()Returns a deep copy of the worst value in the top.The worst is the greatest value for
SortOrder.ASC, and the lowest value forSortOrder.DESC.This always allocates. Hot callers that only need to compare against the worst value should prefer
getWorstValueView()— which returns a view that is invalidated by the next mutation of this set. -
getWorstValueView
public org.apache.lucene.util.BytesRef getWorstValueView()Returns a non-owningBytesRefview of the worst value in the top.The returned reference is only valid until the next mutating call on this set (
collect(BytesRef),reduceLimitByOne(),close()). Callers that need to keep the bytes across mutations must usegetWorstValue()instead. -
getOrder
The order of the sort. -
getLimit
public int getLimit() -
getCount
public int getCount() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReleasable
-