| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart._collection.dev; | 5 part of dart._collection.dev; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Dual-Pivot Quicksort algorithm. | 8 * Dual-Pivot Quicksort algorithm. |
| 9 * | 9 * |
| 10 * This class implements the dual-pivot quicksort algorithm as presented in | 10 * This class implements the dual-pivot quicksort algorithm as presented in |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 throw "OutOfRange"; | 47 throw "OutOfRange"; |
| 48 } | 48 } |
| 49 _doSort(a, from, to - 1, compare); | 49 _doSort(a, from, to - 1, compare); |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Sorts the list in the interval [:left:] to [:right:] (both inclusive). | 53 * Sorts the list in the interval [:left:] to [:right:] (both inclusive). |
| 54 */ | 54 */ |
| 55 static void _doSort(List a, int left, int right, int compare(a, b)) { | 55 static void _doSort(List a, int left, int right, int compare(a, b)) { |
| 56 if ((right - left) <= _INSERTION_SORT_THRESHOLD) { | 56 if ((right - left) <= _INSERTION_SORT_THRESHOLD) { |
| 57 insertionSort_(a, left, right, compare); | 57 _insertionSort(a, left, right, compare); |
| 58 } else { | 58 } else { |
| 59 _dualPivotQuicksort(a, left, right, compare); | 59 _dualPivotQuicksort(a, left, right, compare); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 static void insertionSort_(List a, int left, int right, int compare(a, b)) { | 63 static void _insertionSort(List a, int left, int right, int compare(a, b)) { |
| 64 for (int i = left + 1; i <= right; i++) { | 64 for (int i = left + 1; i <= right; i++) { |
| 65 var el = a[i]; | 65 var el = a[i]; |
| 66 int j = i; | 66 int j = i; |
| 67 while ((j > left) && (compare(a[j - 1], el) > 0)) { | 67 while ((j > left) && (compare(a[j - 1], el) > 0)) { |
| 68 a[j] = a[j - 1]; | 68 a[j] = a[j - 1]; |
| 69 j--; | 69 j--; |
| 70 } | 70 } |
| 71 a[j] = el; | 71 a[j] = el; |
| 72 } | 72 } |
| 73 } | 73 } |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } else { | 335 } else { |
| 336 // The second partition looks as follows: | 336 // The second partition looks as follows: |
| 337 // [ * | >= pivot1 && <= pivot2 | * ] | 337 // [ * | >= pivot1 && <= pivot2 | * ] |
| 338 // ^ ^ | 338 // ^ ^ |
| 339 // less great | 339 // less great |
| 340 // Simply sort it by recursive descent. | 340 // Simply sort it by recursive descent. |
| 341 _doSort(a, less, great, compare); | 341 _doSort(a, less, great, compare); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 } | 344 } |
| OLD | NEW |