public class ListSort<T>
extends java.lang.Object
Disclaimer : I was intrigued by the use of val >>> 1 in java 7 Timsort class
instead of val / 2 (integer division). Micro benching revealed that val >>> 1
is twice faster than val / 2 in java 6 and has similar perf in java 7. The
following code uses val >>> 1 when ever a value needs to be divided by 2 and
rounded to its floor
Constructor and Description |
---|
ListSort()
Creates a ListSort
|
Modifier and Type | Method and Description |
---|---|
void |
allocateStack(int len)
Allocate temp variables for the given length This method should be called
at least once, but only if the length of the list to sort changed before
sorting
|
int |
getLength()
return the useful length of the array being sorted
|
void |
innerMergeHigh(java.util.Comparator<T> comp,
T[] tempArray,
T[] arr,
int idxA)
Attempt to unroll "goto" style original implementation.
|
void |
innerMergeLow(java.util.Comparator<T> comp,
T[] arr,
T[] tempArray)
Attempt to unroll "goto" style original implementation.
|
static void |
main(java.lang.String[] argv)
test case
|
void |
sort(T[] array,
java.util.Comparator<T> comparator)
Sort the given array given the comparator
|
public final void allocateStack(int len)
len
- the size of the array to sortpublic void sort(T[] array, java.util.Comparator<T> comparator)
array
- the array to sortcomparator
- the comparator to compare elements of the arraypublic void innerMergeLow(java.util.Comparator<T> comp, T[] arr, T[] tempArray)
comp
- comparatorarr
- the arraytempArray
- the temp arraypublic void innerMergeHigh(java.util.Comparator<T> comp, T[] tempArray, T[] arr, int idxA)
comp
- comparatorarr
- the arraytempArray
- the temp arrayidxA
- the index of the first element of run Apublic int getLength()
public static void main(java.lang.String[] argv)
argv
- ignored