Chromium Code Reviews| 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 // TODO(ajohnsen): Remove once coreimpl is eliminated. | |
| 6 void coreSort(List l, int compare(a, b)) => _Sort.sort(l, compare); | |
|
floitsch
2012/10/23 17:25:29
Add a dartdoc explaining that this method will go
Anders Johnsen
2012/10/23 17:33:00
Done.
| |
| 7 | |
| 5 /** | 8 /** |
| 6 * Dual-Pivot Quicksort algorithm. | 9 * Dual-Pivot Quicksort algorithm. |
| 7 * | 10 * |
| 8 * This class implements the dual-pivot quicksort algorithm as presented in | 11 * This class implements the dual-pivot quicksort algorithm as presented in |
| 9 * Vladimir Yaroslavskiy's paper. | 12 * Vladimir Yaroslavskiy's paper. |
| 10 * | 13 * |
| 11 * Some improvements have been copied from Android's implementation. | 14 * Some improvements have been copied from Android's implementation. |
| 12 */ | 15 */ |
| 13 class DualPivotQuicksort { | 16 class _Sort { |
| 14 // When a list has less then [:_INSERTION_SORT_THRESHOLD:] elements it will | 17 // When a list has less then [:_INSERTION_SORT_THRESHOLD:] elements it will |
| 15 // be sorted by an insertion sort. | 18 // be sorted by an insertion sort. |
| 16 static const int _INSERTION_SORT_THRESHOLD = 32; | 19 static const int _INSERTION_SORT_THRESHOLD = 32; |
| 17 | 20 |
| 18 /** | 21 /** |
| 19 * Sorts all elements of the given list [:a:] according to the given | 22 * Sorts all elements of the given list [:a:] according to the given |
| 20 * [:compare:] function. | 23 * [:compare:] function. |
| 21 * | 24 * |
| 22 * The [:compare:] function takes two arguments [:x:] and [:y:] and returns | 25 * The [:compare:] function takes two arguments [:x:] and [:y:] and returns |
| 23 * -1 if [:x < y:], | 26 * -1 if [:x < y:], |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 } else { | 336 } else { |
| 334 // The second partition looks as follows: | 337 // The second partition looks as follows: |
| 335 // [ * | >= pivot1 && <= pivot2 | * ] | 338 // [ * | >= pivot1 && <= pivot2 | * ] |
| 336 // ^ ^ | 339 // ^ ^ |
| 337 // less great | 340 // less great |
| 338 // Simply sort it by recursive descent. | 341 // Simply sort it by recursive descent. |
| 339 _doSort(a, less, great, compare); | 342 _doSort(a, less, great, compare); |
| 340 } | 343 } |
| 341 } | 344 } |
| 342 } | 345 } |
| OLD | NEW |