java.lang.Object
org.apache.lucene.util.Sorter
- Direct Known Subclasses:
InPlaceMergeSorter,IntroSorter,MSBRadixSorter,StableMSBRadixSorter.MergeSorter,StringSorter,TimSorter
Base class for sorting algorithms implementations.
There are a number of subclasses to choose from that vary in performance and stability. We suggest that you pick the first from this ranked list that meets your requirements:
MSBRadixSorterfor strings (array of bytes/chars). Not a stable sort.StableMSBRadixSorterfor strings (array of bytes/chars). Stable sort.IntroSorter. Not a stable sort.InPlaceMergeSorter. When the data to sort is typically small. Stable sort.TimSorter. Stable sort.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int(package private) static final intBelow this size threshold, the sub-range is sorted using Insertion sort.private int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidbinarySort(int from, int to) A binary sort implementation.(package private) voidbinarySort(int from, int to, int i) (package private) voidcheckRange(int from, int to) protected abstract intcompare(int i, int j) Compare entries found in slotsiandj.protected intcomparePivot(int j) Compare the pivot with the slot atj, similarly tocompare(i, j).(package private) voiddoRotate(int lo, int mid, int hi) (package private) static intheapChild(int from, int i) (package private) voidheapify(int from, int to) (package private) static intheapParent(int from, int i) (package private) voidheapSort(int from, int to) Use heap sort to sort items betweenfrominclusive andtoexclusive.(package private) voidinsertionSort(int from, int to) Sorts between from (inclusive) and to (exclusive) with insertion sort.(package private) intlower(int from, int to, int val) (package private) intlower2(int from, int to, int val) (package private) voidmergeInPlace(int from, int mid, int to) (package private) final voidreverse(int from, int to) (package private) final voidrotate(int lo, int mid, int hi) protected voidsetPivot(int i) Save the value at slotiso that it can later be used as a pivot, seecomparePivot(int).(package private) voidsiftDown(int i, int from, int to) abstract voidsort(int from, int to) Sort the slice which starts atfrom(inclusive) and ends atto(exclusive).protected abstract voidswap(int i, int j) Swap values at slotsiandj.(package private) intupper(int from, int to, int val) (package private) intupper2(int from, int to, int val)
-
Field Details
-
BINARY_SORT_THRESHOLD
static final int BINARY_SORT_THRESHOLD- See Also:
-
INSERTION_SORT_THRESHOLD
static final int INSERTION_SORT_THRESHOLDBelow this size threshold, the sub-range is sorted using Insertion sort.- See Also:
-
pivotIndex
private int pivotIndex
-
-
Constructor Details
-
Sorter
protected Sorter()Sole constructor, used for inheritance.
-
-
Method Details
-
compare
protected abstract int compare(int i, int j) Compare entries found in slotsiandj. The contract for the returned value is the same asComparator.compare(Object, Object). -
swap
protected abstract void swap(int i, int j) Swap values at slotsiandj. -
setPivot
protected void setPivot(int i) Save the value at slotiso that it can later be used as a pivot, seecomparePivot(int). -
comparePivot
protected int comparePivot(int j) Compare the pivot with the slot atj, similarly tocompare(i, j). -
sort
public abstract void sort(int from, int to) Sort the slice which starts atfrom(inclusive) and ends atto(exclusive). -
checkRange
void checkRange(int from, int to) -
mergeInPlace
void mergeInPlace(int from, int mid, int to) -
lower
int lower(int from, int to, int val) -
upper
int upper(int from, int to, int val) -
lower2
int lower2(int from, int to, int val) -
upper2
int upper2(int from, int to, int val) -
reverse
final void reverse(int from, int to) -
rotate
final void rotate(int lo, int mid, int hi) -
doRotate
void doRotate(int lo, int mid, int hi) -
binarySort
void binarySort(int from, int to) A binary sort implementation. This performsO(n*log(n))comparisons andO(n^2)swaps. It is typically used by more sophisticated implementations as a fall-back when the number of items to sort has become less than 20. This algorithm is stable. -
binarySort
void binarySort(int from, int to, int i) -
insertionSort
void insertionSort(int from, int to) Sorts between from (inclusive) and to (exclusive) with insertion sort. Runs inO(n^2). It is typically used by more sophisticated implementations as a fall-back when the number of items to sort becomes less than 16. This algorithm is stable. -
heapSort
void heapSort(int from, int to) Use heap sort to sort items betweenfrominclusive andtoexclusive. This runs inO(n*log(n))and is used as a fall-back byIntroSorter. This algorithm is NOT stable. -
heapify
void heapify(int from, int to) -
siftDown
void siftDown(int i, int from, int to) -
heapParent
static int heapParent(int from, int i) -
heapChild
static int heapChild(int from, int i)
-