Package org.apache.lucene.util
Class IntroSelector
java.lang.Object
org.apache.lucene.util.Selector
org.apache.lucene.util.IntroSelector
Adaptive selection algorithm based on the introspective quick select algorithm. The quick select
algorithm uses an interpolation variant of Tukey's ninther median-of-medians for pivot, and
Bentley-McIlroy 3-way partitioning. For the introspective protection, it shuffles the sub-range
if the max recursive depth is exceeded.
This selection algorithm is fast on most data shapes, especially on nearly sorted data, or when k is close to the boundaries. It runs in linear time on average.
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected int
compare
(int i, int j) Compare entries found in slotsi
andj
.protected abstract int
comparePivot
(int j) Compare the pivot with the slot atj
, similarly tocompare(i, j)
.final void
select
(int from, int to, int k) Reorder elements so that the element at positionk
is the same as if all elements were sorted and all other elements are partitioned around it:[from, k)
only contains elements that are less than or equal tok
and(k, to)
only contains elements that are greater than or equal tok
.protected abstract void
setPivot
(int i) Save the value at sloti
so that it can later be used as a pivot, seecomparePivot(int)
.
-
Constructor Details
-
IntroSelector
public IntroSelector()
-
-
Method Details
-
select
public final void select(int from, int to, int k) Description copied from class:Selector
Reorder elements so that the element at positionk
is the same as if all elements were sorted and all other elements are partitioned around it:[from, k)
only contains elements that are less than or equal tok
and(k, to)
only contains elements that are greater than or equal tok
. -
setPivot
protected abstract void setPivot(int i) Save the value at sloti
so that it can later be used as a pivot, seecomparePivot(int)
. -
comparePivot
protected abstract int comparePivot(int j) Compare the pivot with the slot atj
, similarly tocompare(i, j)
. -
compare
protected int compare(int i, int j) Compare entries found in slotsi
andj
. The contract for the returned value is the same asComparator.compare(Object, Object)
.
-