Package org.apache.lucene.util
Class SorterTemplate
- java.lang.Object
-
- org.apache.lucene.util.SorterTemplate
-
public abstract class SorterTemplate extends Object
This class was inspired by CGLIB, but provides a better QuickSort algorithm without additional InsertionSort at the end. To use, subclass and override the four abstract methods which compare and modify your data. Allows custom swap so that two arrays can be sorted at the same time.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Constructor Summary
Constructors Constructor Description SorterTemplate()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract intcompare(int i, int j)Compares slotsiandjof you data.protected abstract intcomparePivot(int j)Implements the compare function for the previously stored pivot value.voidinsertionSort(int lo, int hi)Sorts via stable in-place InsertionSort algorithm (ideal for small collections which are mostly presorted).voidmergeSort(int lo, int hi)Sorts via stable in-place MergeSort algorithm For small collections falls back toinsertionSort(int,int).voidquickSort(int lo, int hi)Sorts via in-place, but unstable, QuickSort algorithm.protected abstract voidsetPivot(int i)Implement this method, that stores the value of slotias pivot valueprotected abstract voidswap(int i, int j)Implement this method, that swaps slotsiandjin your data
-
-
-
Method Detail
-
swap
protected abstract void swap(int i, int j)Implement this method, that swaps slotsiandjin your data
-
compare
protected abstract int compare(int i, int j)Compares slotsiandjof you data. Should be implemented likevalueOf(i).compareTo(valueOf(j))
-
setPivot
protected abstract void setPivot(int i)
Implement this method, that stores the value of slotias pivot value
-
comparePivot
protected abstract int comparePivot(int j)
Implements the compare function for the previously stored pivot value. Should be implemented likepivot.compareTo(valueOf(j))
-
insertionSort
public final void insertionSort(int lo, int hi)Sorts via stable in-place InsertionSort algorithm (ideal for small collections which are mostly presorted).
-
quickSort
public final void quickSort(int lo, int hi)Sorts via in-place, but unstable, QuickSort algorithm. For small collections falls back toinsertionSort(int,int).
-
mergeSort
public final void mergeSort(int lo, int hi)Sorts via stable in-place MergeSort algorithm For small collections falls back toinsertionSort(int,int).
-
-