Package org.apache.lucene.util
Class TimSorter
- java.lang.Object
-
- org.apache.lucene.util.Sorter
-
- org.apache.lucene.util.TimSorter
-
public abstract class TimSorter extends Sorter
Sorter
implementation 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
maxTempSlots
equal 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.
- 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
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract int
compareSaved(int i, int j)
Compare elementi
from the temporary storage with elementj
from the slice to sort, similarly toSorter.compare(int, int)
.protected abstract void
copy(int src, int dest)
Copy data from slotsrc
to slotdest
.protected abstract void
restore(int i, int j)
Restore elementj
from the temporary storage into sloti
.protected abstract void
save(int i, int len)
Save all elements between slotsi
andi+len
into the temporary storage.void
sort(int from, int to)
Sort the slice which starts atfrom
(inclusive) and ends atto
(exclusive).
-
-
-
Constructor Detail
-
TimSorter
protected TimSorter(int maxTempSlots)
Create a newTimSorter
.- Parameters:
maxTempSlots
- the maximum amount of extra memory to run merges
-
-
Method Detail
-
sort
public void sort(int from, int to)
Description copied from class:Sorter
Sort the slice which starts atfrom
(inclusive) and ends atto
(exclusive).
-
copy
protected abstract void copy(int src, int dest)
Copy data from slotsrc
to slotdest
.
-
save
protected abstract void save(int i, int len)
Save all elements between slotsi
andi+len
into the temporary storage.
-
restore
protected abstract void restore(int i, int j)
Restore elementj
from the temporary storage into sloti
.
-
compareSaved
protected abstract int compareSaved(int i, int j)
Compare elementi
from the temporary storage with elementj
from the slice to sort, similarly toSorter.compare(int, int)
.
-
-