Package org.apache.lucene.util
Class TimSorter
- java.lang.Object
-
- org.apache.lucene.util.Sorter
-
- org.apache.lucene.util.TimSorter
-
- Direct Known Subclasses:
ArrayTimSorter,CollectionUtil.ListTimSorter,FreqProxTermsWriter.SortingDocsEnum.DocFreqSorter,FreqProxTermsWriter.SortingPostingsEnum.DocOffsetSorter,Sorter.DocValueSorter
public abstract class TimSorter extends Sorter
Sorterimplementation based on the TimSort algorithm.This implementation is especially good at sorting partially-sorted arrays and sorts small arrays with binary sort.
NOTE:There are a few differences with the original implementation:
- The extra amount of memory to perform merges is
configurable. This allows small merges to be very fast while large merges
will be performed in-place (slightly slower). You can make sure that the
fast merge routine will always be used by having
maxTempSlotsequal to half of the length of the slice of data to sort. - Only the fast merge routine can gallop (the one that doesn't run in-place) and it only gallops on the longest slice.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) intmaxTempSlots(package private) static intMIN_GALLOP(package private) intminRun(package private) static intMINRUN(package private) int[]runEnds(package private) intstackSize(package private) static intSTACKSIZE(package private) static intTHRESHOLD(package private) intto-
Fields inherited from class org.apache.lucene.util.Sorter
BINARY_SORT_THRESHOLD
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract intcompareSaved(int i, int j)Compare elementifrom the temporary storage with elementjfrom the slice to sort, similarly toSorter.compare(int, int).protected abstract voidcopy(int src, int dest)Copy data from slotsrcto slotdest.(package private) voiddoRotate(int lo, int mid, int hi)(package private) voidensureInvariants()(package private) voidexhaustStack()(package private) intlowerSaved(int from, int to, int val)(package private) intlowerSaved3(int from, int to, int val)(package private) voidmerge(int lo, int mid, int hi)(package private) voidmergeAt(int n)(package private) voidmergeHi(int lo, int mid, int hi)(package private) voidmergeLo(int lo, int mid, int hi)(package private) static intminRun(int length)Minimum run length for an array of lengthlength.(package private) intnextRun()Compute the length of the next run, make the run sorted and return its length.(package private) voidpushRunLen(int len)(package private) voidreset(int from, int to)protected abstract voidrestore(int i, int j)Restore elementjfrom the temporary storage into sloti.(package private) intrunBase(int i)(package private) intrunEnd(int i)(package private) intrunLen(int i)protected abstract voidsave(int i, int len)Save all elements between slotsiandi+leninto the temporary storage.(package private) voidsetRunEnd(int i, int runEnd)voidsort(int from, int to)Sort the slice which starts atfrom(inclusive) and ends atto(exclusive).(package private) intupperSaved(int from, int to, int val)(package private) intupperSaved3(int from, int to, int val)-
Methods inherited from class org.apache.lucene.util.Sorter
binarySort, binarySort, checkRange, compare, comparePivot, heapChild, heapify, heapParent, heapSort, lower, lower2, mergeInPlace, reverse, rotate, setPivot, siftDown, swap, upper, upper2
-
-
-
-
Field Detail
-
MINRUN
static final int MINRUN
- See Also:
- Constant Field Values
-
THRESHOLD
static final int THRESHOLD
- See Also:
- Constant Field Values
-
STACKSIZE
static final int STACKSIZE
- See Also:
- Constant Field Values
-
MIN_GALLOP
static final int MIN_GALLOP
- See Also:
- Constant Field Values
-
maxTempSlots
final int maxTempSlots
-
minRun
int minRun
-
to
int to
-
stackSize
int stackSize
-
runEnds
int[] runEnds
-
-
Constructor Detail
-
TimSorter
protected TimSorter(int maxTempSlots)
Create a newTimSorter.- Parameters:
maxTempSlots- the maximum amount of extra memory to run merges
-
-
Method Detail
-
minRun
static int minRun(int length)
Minimum run length for an array of lengthlength.
-
runLen
int runLen(int i)
-
runBase
int runBase(int i)
-
runEnd
int runEnd(int i)
-
setRunEnd
void setRunEnd(int i, int runEnd)
-
pushRunLen
void pushRunLen(int len)
-
nextRun
int nextRun()
Compute the length of the next run, make the run sorted and return its length.
-
ensureInvariants
void ensureInvariants()
-
exhaustStack
void exhaustStack()
-
reset
void reset(int from, int to)
-
mergeAt
void mergeAt(int n)
-
merge
void merge(int lo, int mid, int hi)
-
sort
public void sort(int from, int to)Description copied from class:SorterSort the slice which starts atfrom(inclusive) and ends atto(exclusive).
-
mergeLo
void mergeLo(int lo, int mid, int hi)
-
mergeHi
void mergeHi(int lo, int mid, int hi)
-
lowerSaved
int lowerSaved(int from, int to, int val)
-
upperSaved
int upperSaved(int from, int to, int val)
-
lowerSaved3
int lowerSaved3(int from, int to, int val)
-
upperSaved3
int upperSaved3(int from, int to, int val)
-
copy
protected abstract void copy(int src, int dest)Copy data from slotsrcto slotdest.
-
save
protected abstract void save(int i, int len)Save all elements between slotsiandi+leninto the temporary storage.
-
restore
protected abstract void restore(int i, int j)Restore elementjfrom the temporary storage into sloti.
-
compareSaved
protected abstract int compareSaved(int i, int j)Compare elementifrom the temporary storage with elementjfrom the slice to sort, similarly toSorter.compare(int, int).
-
-