ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/ComparableTimSort.java
(Generate patch)

Comparing jsr166/src/main/java/util/ComparableTimSort.java (file contents):
Revision 1.1 by jsr166, Tue Sep 1 01:40:03 2009 UTC vs.
Revision 1.4 by jsr166, Sun Nov 21 08:15:12 2010 UTC

# Line 14 | Line 14
14   * limitations under the License.
15   */
16  
17 < import java.util.*;
17 > package java.util;
18  
19   /**
20   * This is a near duplicate of {@link TimSort}, modified for use with
# Line 26 | Line 26 | import java.util.*;
26   * comparator that simply returns {@code ((Comparable)first).compareTo(Second)}.
27   * If this is the case, you are better off deleting ComparableTimSort to
28   * eliminate the code duplication.  (See Arrays.java for details.)
29 + *
30 + * @author Josh Bloch
31   */
32   class ComparableTimSort {
33      /**
# Line 143 | Line 145 | class ComparableTimSort {
145  
146          // If array is small, do a "mini-TimSort" with no merges
147          if (nRemaining < MIN_MERGE) {
148 <            int initRunLen = countRunAndMakeAscending(a, lo, nRemaining);
148 >            int initRunLen = countRunAndMakeAscending(a, lo, hi);
149              binarySort(a, lo, hi, lo + initRunLen);
150              return;
151          }
# Line 196 | Line 198 | class ComparableTimSort {
198       * @param lo the index of the first element in the range to be sorted
199       * @param hi the index after the last element in the range to be sorted
200       * @param start the index of the first element in the range that is
201 <     *        not already known to be sorted (@code lo <= start <= hi}
201 >     *        not already known to be sorted ({@code lo <= start <= hi})
202       */
203      @SuppressWarnings("fallthrough")
204      private static void binarySort(Object[] a, int lo, int hi, int start) {
# Line 234 | Line 236 | class ComparableTimSort {
236               */
237              int n = start - left;  // The number of elements to move
238              // Switch is just an optimization for arraycopy in default case
239 <            switch(n) {
239 >            switch (n) {
240                  case 2:  a[left + 2] = a[left + 1];
241                  case 1:  a[left + 1] = a[left];
242                           break;
# Line 264 | Line 266 | class ComparableTimSort {
266       * @param a the array in which a run is to be counted and possibly reversed
267       * @param lo index of the first element in the run
268       * @param hi index after the last element that may be contained in the run.
269 <              It is required that @code{lo < hi}.
269 >              It is required that {@code lo < hi}.
270       * @return  the length of the run beginning at the specified position in
271       *          the specified array
272       */
# Line 277 | Line 279 | class ComparableTimSort {
279  
280          // Find end of run, and reverse range if descending
281          if (((Comparable) a[runHi++]).compareTo(a[lo]) < 0) { // Descending
282 <            while(runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) < 0)
282 >            while (runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) < 0)
283                  runHi++;
284              reverseRange(a, lo, runHi);
285          } else {                              // Ascending
# Line 668 | Line 670 | class ComparableTimSort {
670                      dest += count1;
671                      cursor1 += count1;
672                      len1 -= count1;
673 <                    if (len1 <= 1) // len1 == 1 || len1 == 0
673 >                    if (len1 <= 1)  // len1 == 1 || len1 == 0
674                          break outer;
675                  }
676                  a[dest++] = a[cursor2++];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines