Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1818)

Unified Diff: corelib/src/implementation/dual_pivot_quicksort.dart

Issue 8510047: Fix dual-pivot sort. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove printing. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/co19/co19-compiler.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: corelib/src/implementation/dual_pivot_quicksort.dart
diff --git a/corelib/src/implementation/dual_pivot_quicksort.dart b/corelib/src/implementation/dual_pivot_quicksort.dart
index 3f517628956b402827269486b27d0304daec298d..38b3b96ddfb2f083285accc65c9ec038d62605a9 100644
--- a/corelib/src/implementation/dual_pivot_quicksort.dart
+++ b/corelib/src/implementation/dual_pivot_quicksort.dart
@@ -78,10 +78,10 @@ class DualPivotQuicksort {
// Compute the two pivots by looking at 5 elements.
int sixth = (right - left + 1) ~/ 6;
int index1 = left + sixth;
- int index2 = index1 + sixth;
- int index3 = right - sixth;
- int index4 = index3 - sixth;
- int index5 = (left + right) ~/ 2;
+ int index5 = right - sixth;
+ int index3 = (left + right) ~/ 2; // The midpoint.
+ int index2 = index3 - sixth;
+ int index4 = index3 + sixth;
var el1 = a[index1];
var el2 = a[index2];
@@ -154,19 +154,19 @@ class DualPivotQuicksort {
// pivots are put into their final positions.
while (true) {
int comp = compare(a[great], pivot);
- if (comp < 0) {
+ if (comp > 0) {
great--;
// This is the only location in the while-loop where a new
// iteration is started.
continue;
- } else if (comp == 0) {
+ } else if (comp < 0) {
// Triple exchange.
a[k] = a[less];
a[less++] = a[great];
a[great--] = ak;
break;
} else {
- // comp > 0;
+ // comp == 0;
a[k] = a[great];
a[great--] = ak;
// Note: if great < k then we will exit the outer loop and fix
@@ -307,13 +307,13 @@ class DualPivotQuicksort {
} else {
// a[great] < pivot2.
int comp = compare(a[great], pivot1);
- if (comp == 0) {
+ if (comp < 0) {
// Triple exchange.
a[k] = a[less];
a[less++] = a[great];
a[great--] = ak;
} else {
- // a[great] > pivot1.
+ // a[great] == pivot1.
a[k] = a[great];
a[great--] = ak;
}
« no previous file with comments | « no previous file | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698