|
@@ -53,11 +53,11 @@ import java.util.Comparator;
|
|
* list changes
|
|
* list changes
|
|
*
|
|
*
|
|
* {@code
|
|
* {@code
|
|
- * 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
|
|
|
|
|
|
+ * Disclaimer : I was intrigued by the use of val >>> 1 in the Java7 Timsort
|
|
|
|
+ * in place of val / 2 (integer division). Micro benching revealed that val >>> 1
|
|
|
|
+ * is twice as fast as val / 2 in Java6 and has similar perf in Java7. The
|
|
|
|
+ * following code uses val >>> 1 whenever a value needs to be divided by 2 and
|
|
|
|
+ * rounded to its floor.
|
|
* }
|
|
* }
|
|
*
|
|
*
|
|
* @author Nehon
|
|
* @author Nehon
|
|
@@ -75,14 +75,14 @@ public class ListSort<T> {
|
|
private Comparator<T> comparator;
|
|
private Comparator<T> comparator;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * attribute temp vars for merging. This was used to unroll the merge_lo &
|
|
|
|
|
|
+ * Attribute temp vars for merging. This was used to unroll the merge_lo &
|
|
* merge_hi function of original implementations that used massive labeled
|
|
* merge_hi function of original implementations that used massive labeled
|
|
- * goto branching and was almost unreadable
|
|
|
|
|
|
+ * goto branching and was almost unreadable.
|
|
*/
|
|
*/
|
|
int iterA, iterB, dest, lengthA, lengthB;
|
|
int iterA, iterB, dest, lengthA, lengthB;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Number of runs to merge
|
|
|
|
|
|
+ * Number of runs to merge.
|
|
*/
|
|
*/
|
|
private int nbRuns = 0;
|
|
private int nbRuns = 0;
|
|
|
|
|
|
@@ -92,13 +92,13 @@ public class ListSort<T> {
|
|
* class + array was a convoluted pain.
|
|
* class + array was a convoluted pain.
|
|
*/
|
|
*/
|
|
/**
|
|
/**
|
|
- * array of start indices in the original array for runs : run i starting
|
|
|
|
- * index is at runIndices[i]
|
|
|
|
|
|
+ * Array of run start indices in the original array: starting
|
|
|
|
+ * index of run 'i' is at runIndices[i].
|
|
*/
|
|
*/
|
|
private int[] runsIndices = null;
|
|
private int[] runsIndices = null;
|
|
/**
|
|
/**
|
|
- * array of runs length in the original array : run i length is at
|
|
|
|
- * runLength[i]
|
|
|
|
|
|
+ * Array of run lengths in the original array: length of run 'i' is at
|
|
|
|
+ * runLength[i].
|
|
*/
|
|
*/
|
|
private int[] runsLength = null;
|
|
private int[] runsLength = null;
|
|
/**
|
|
/**
|
|
@@ -109,12 +109,12 @@ public class ListSort<T> {
|
|
/**
|
|
/**
|
|
* MIN_GALLOP set to 7 constant as described in listsort.txt. this magic
|
|
* MIN_GALLOP set to 7 constant as described in listsort.txt. this magic
|
|
* number indicates how many wins should trigger the switch from binary
|
|
* number indicates how many wins should trigger the switch from binary
|
|
- * search to galloping mode
|
|
|
|
|
|
+ * search to galloping mode.
|
|
*/
|
|
*/
|
|
private static final int MIN_GALLOP = 7;
|
|
private static final int MIN_GALLOP = 7;
|
|
/**
|
|
/**
|
|
- * This variable allows to adjust when switching to galloping mode. lowered
|
|
|
|
- * when the data are "naturally" structured, raised when data are random.
|
|
|
|
|
|
+ * Controls switching to galloping mode. It is lowered
|
|
|
|
+ * when the data are "naturally" ordered and raised when they are random.
|
|
*/
|
|
*/
|
|
private int minGallop = MIN_GALLOP;
|
|
private int minGallop = MIN_GALLOP;
|
|
|
|
|
|
@@ -670,9 +670,9 @@ public class ListSort<T> {
|
|
* lenA <= lenB. See listsort.txt for more info.
|
|
* lenA <= lenB. See listsort.txt for more info.
|
|
*
|
|
*
|
|
* @param idxA index of first element in run A
|
|
* @param idxA index of first element in run A
|
|
- * @param lengthA length of run A
|
|
|
|
|
|
+ * @param lenA length of run A
|
|
* @param idxB index of first element in run B
|
|
* @param idxB index of first element in run B
|
|
- * @param lengthB length of run B
|
|
|
|
|
|
+ * @param lenB length of run B
|
|
*/
|
|
*/
|
|
private void mergeLow(int idxA, int lenA, int idxB, int lenB) {
|
|
private void mergeLow(int idxA, int lenA, int idxB, int lenB) {
|
|
|
|
|
|
@@ -822,9 +822,9 @@ public class ListSort<T> {
|
|
* lenA >= lenB. See listsort.txt for more info.
|
|
* lenA >= lenB. See listsort.txt for more info.
|
|
*
|
|
*
|
|
* @param idxA index of first element in run A
|
|
* @param idxA index of first element in run A
|
|
- * @param lengthA length of run A
|
|
|
|
|
|
+ * @param lenA length of run A
|
|
* @param idxB index of first element in run B
|
|
* @param idxB index of first element in run B
|
|
- * @param lengthB length of run B
|
|
|
|
|
|
+ * @param lenB length of run B
|
|
*/
|
|
*/
|
|
private void mergeHigh(int idxA, int lenA, int idxB, int lenB) {
|
|
private void mergeHigh(int idxA, int lenA, int idxB, int lenB) {
|
|
|
|
|