Package org.apache.lucene.util
Class TimSorter
java.lang.Object
org.apache.lucene.util.Sorter
org.apache.lucene.util.TimSorter
Sorter implementation based on the TimSort algorithm. It
sorts small arrays with a binary sort.
This algorithm is stable. It's especially good at sorting partially-sorted arrays.
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.
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.protected abstract voidrestore(int i, int j) Restore elementjfrom the temporary storage into sloti.protected abstract voidsave(int i, int len) Save all elements between slotsiandi+leninto the temporary storage.voidsort(int from, int to) Sort the slice which starts atfrom(inclusive) and ends atto(exclusive).Methods inherited from class org.apache.lucene.util.Sorter
compare, comparePivot, setPivot, swap
-
Constructor Details
-
TimSorter
protected TimSorter(int maxTempSlots) Create a newTimSorter.- Parameters:
maxTempSlots- the maximum amount of extra memory to run merges
-
-
Method Details
-
sort
public void sort(int from, int to) Description copied from class:SorterSort the slice which starts atfrom(inclusive) and ends atto(exclusive). -
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).
-