Package org.apache.lucene.util
Class IntroSelector
- java.lang.Object
-
- org.apache.lucene.util.Selector
-
- org.apache.lucene.util.IntroSelector
-
public abstract class IntroSelector extends Selector
Implementation of the quick select algorithm.It uses the median of the first, middle and last values as a pivot and falls back to a heap sort when the number of recursion levels exceeds
2 lg(n)
, as a consequence it runs in linear time on average and inn log(n)
time in the worst case.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Constructor Summary
Constructors Constructor Description IntroSelector()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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)
.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)
.
-
-
-
Method Detail
-
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
.
-
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)
.
-
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)
.
-
-