14 |
|
* limitations under the License. |
15 |
|
*/ |
16 |
|
|
17 |
< |
import java.util.*; |
17 |
> |
package java.util; |
18 |
|
|
19 |
|
/** |
20 |
|
* A stable, adaptive, iterative mergesort that requires far fewer than |
46 |
|
* (privately) instantiable; a TimSort instance holds the state of an ongoing |
47 |
|
* sort, assuming the input array is large enough to warrant the full-blown |
48 |
|
* TimSort. Small arrays are sorted in place, using a binary insertion sort. |
49 |
+ |
* |
50 |
+ |
* @author Josh Bloch |
51 |
|
*/ |
52 |
|
class TimSort<T> { |
53 |
|
/** |
177 |
|
|
178 |
|
// If array is small, do a "mini-TimSort" with no merges |
179 |
|
if (nRemaining < MIN_MERGE) { |
180 |
< |
int initRunLen = countRunAndMakeAscending(a, lo, nRemaining, c); |
180 |
> |
int initRunLen = countRunAndMakeAscending(a, lo, hi, c); |
181 |
|
binarySort(a, lo, hi, lo + initRunLen, c); |
182 |
|
return; |
183 |
|
} |
269 |
|
*/ |
270 |
|
int n = start - left; // The number of elements to move |
271 |
|
// Switch is just an optimization for arraycopy in default case |
272 |
< |
switch(n) { |
272 |
> |
switch (n) { |
273 |
|
case 2: a[left + 2] = a[left + 1]; |
274 |
|
case 1: a[left + 1] = a[left]; |
275 |
|
break; |
313 |
|
|
314 |
|
// Find end of run, and reverse range if descending |
315 |
|
if (c.compare(a[runHi++], a[lo]) < 0) { // Descending |
316 |
< |
while(runHi < hi && c.compare(a[runHi], a[runHi - 1]) < 0) |
316 |
> |
while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) < 0) |
317 |
|
runHi++; |
318 |
|
reverseRange(a, lo, runHi); |
319 |
|
} else { // Ascending |