Package org.apache.lucene.util
Class IntroSorter
java.lang.Object
org.apache.lucene.util.Sorter
org.apache.lucene.util.IntroSorter
Sorter
implementation based on a variant of the quicksort algorithm called introsort: when the recursion level exceeds the
log of the length of the array to sort, it falls back to heapsort. This prevents quicksort from
running into its worst-case quadratic runtime. Selects the pivot using Tukey's ninther
median-of-medians, and partitions using Bentley-McIlroy 3-way partitioning. Small ranges are
sorted with insertion sort.
This algorithm is NOT stable. It's fast on most data shapes, especially with low
cardinality. If the data to sort is known to be strictly ascending or descending, prefer TimSorter
.
- 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)
.protected abstract void
setPivot
(int i) Save the value at sloti
so that it can later be used as a pivot, seeSorter.comparePivot(int)
.final void
sort
(int from, int to) Sort the slice which starts atfrom
(inclusive) and ends atto
(exclusive).
-
Constructor Details
-
IntroSorter
public IntroSorter()Create a newIntroSorter
.
-
-
Method Details
-
sort
public final void sort(int from, int to) Description copied from class:Sorter
Sort the slice which starts atfrom
(inclusive) and ends atto
(exclusive). -
setPivot
protected abstract void setPivot(int i) Description copied from class:Sorter
Save the value at sloti
so that it can later be used as a pivot, seeSorter.comparePivot(int)
. -
comparePivot
protected abstract int comparePivot(int j) Description copied from class:Sorter
Compare the pivot with the slot atj
, similarly tocompare(i, j)
.- Overrides:
comparePivot
in classSorter
-
compare
protected int compare(int i, int j) Description copied from class:Sorter
Compare entries found in slotsi
andj
. The contract for the returned value is the same asComparator.compare(Object, Object)
.
-