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
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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.SplittableRandomrandom
-
Constructor Summary
Constructors Constructor Description IntroSelector()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected intcompare(int i, int j)Compare entries found in slotsiandj.protected abstract intcomparePivot(int j)Compare the pivot with the slot atj, similarly tocompare(i, j).private intmax(int i, int j, int k)Returns the index of the max element among three elements at provided indices.private intmedian(int i, int j, int k)Copy ofIntroSorter#median.private intmin(int i, int j, int k)Returns the index of the min element among three elements at provided indices.voidselect(int from, int to, int k)Reorder elements so that the element at positionkis 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 tokand(k, to)only contains elements that are greater than or equal tok.(package private) voidselect(int from, int to, int k, int maxDepth)protected abstract voidsetPivot(int i)Save the value at slotiso that it can later be used as a pivot, seecomparePivot(int).private voidshuffle(int from, int to)Shuffles the entries between from (inclusive) and to (exclusive) with Durstenfeld's algorithm.private voidsort3(int from)Sorts 3 entries starting at from (inclusive).
-
-
-
Method Detail
-
select
public final void select(int from, int to, int k)Description copied from class:SelectorReorder elements so that the element at positionkis 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 tokand(k, to)only contains elements that are greater than or equal tok.
-
select
void select(int from, int to, int k, int maxDepth)
-
min
private int min(int i, int j, int k)Returns the index of the min element among three elements at provided indices.
-
max
private int max(int i, int j, int k)Returns the index of the max element among three elements at provided indices.
-
median
private int median(int i, int j, int k)Copy ofIntroSorter#median.
-
sort3
private void sort3(int from)
Sorts 3 entries starting at from (inclusive). This specialized method is more efficient than callingSorter.insertionSort(int, int).
-
shuffle
private void shuffle(int from, int to)Shuffles the entries between from (inclusive) and to (exclusive) with Durstenfeld's algorithm.
-
setPivot
protected abstract void setPivot(int i)
Save the value at slotiso 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 slotsiandj. The contract for the returned value is the same asComparator.compare(Object, Object).
-
-