--- jsr166/src/extra166y/PAS.java 2010/10/16 16:40:44 1.11 +++ jsr166/src/extra166y/PAS.java 2011/12/05 04:08:47 1.15 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ package extra166y; @@ -676,7 +676,7 @@ class PAS { } } - void atLeaf(int l, int h) { + void atLeaf(int l, int h) { if (pap.hasFilter()) filteredAtLeaf(l, h); else { @@ -689,7 +689,7 @@ class PAS { } } - void filteredAtLeaf(int l, int h) { + void filteredAtLeaf(int l, int h) { for (int i = l; i < h; ++i) { if (pap.isSelected(i)) { Object x = pap.oget(i); @@ -772,7 +772,7 @@ class PAS { } } - void filteredAtLeaf(int l, int h) { + void filteredAtLeaf(int l, int h) { for (int i = l; i < h; ++i) { if (pap.isSelected(i)) { double x = pap.dget(i); @@ -843,7 +843,7 @@ class PAS { } } - void atLeaf(int l, int h) { + void atLeaf(int l, int h) { if (pap.hasFilter()) filteredAtLeaf(l, h); else { @@ -857,7 +857,7 @@ class PAS { } } - void filteredAtLeaf(int l, int h) { + void filteredAtLeaf(int l, int h) { for (int i = l; i < h; ++i) { if (pap.isSelected(i)) { long x = pap.lget(i); @@ -1491,7 +1491,7 @@ class PAS { if ((filtered && !pap.isSelected(k)) || (x = src[k]) == null) continue; - int hc = byIdentity? System.identityHashCode(x): x.hashCode(); + int hc = byIdentity ? System.identityHashCode(x) : x.hashCode(); int hash = hash(hc); long entry = (((long)hash) << 32) + (k + 1); int idx = hash & mask; @@ -1681,7 +1681,7 @@ class PAS { l+h, n-h, l, g, null).compute(); } else - oquickSort(a, cmp, l, l+n-1); + Arrays.sort(a, l, l+n, cmp); } } @@ -1717,7 +1717,7 @@ class PAS { l+h, n-h, l, g, null).compute(); } else - ocquickSort(a, l, l+n-1); + Arrays.sort(a, l, l+n); } } @@ -2307,124 +2307,6 @@ class PAS { // versions of quicksort with comparators - static void oquickSort(Object[] a, Comparator cmp, int lo, int hi) { - for (;;) { - if (hi - lo <= INSERTION_SORT_THRESHOLD) { - for (int i = lo + 1; i <= hi; i++) { - Object t = a[i]; - int j = i - 1; - while (j >= lo && cmp.compare(t, a[j]) < 0) { - a[j+1] = a[j]; - --j; - } - a[j+1] = t; - } - return; - } - - int mid = (lo + hi) >>> 1; - if (cmp.compare(a[lo], a[mid]) > 0) { - Object t = a[lo]; a[lo] = a[mid]; a[mid] = t; - } - if (cmp.compare(a[mid], a[hi]) > 0) { - Object t = a[mid]; a[mid] = a[hi]; a[hi] = t; - if (cmp.compare(a[lo], a[mid]) > 0) { - Object u = a[lo]; a[lo] = a[mid]; a[mid] = u; - } - } - - Object pivot = a[mid]; - int left = lo+1; - int right = hi-1; - boolean sameLefts = true; - for (;;) { - while (cmp.compare(pivot, a[right]) < 0) - --right; - int c; - while (left < right && - (c = cmp.compare(pivot, a[left])) >= 0) { - if (c != 0) - sameLefts = false; - ++left; - } - if (left < right) { - Object t = a[left]; a[left] = a[right]; a[right] = t; - --right; - } - else break; - } - - if (sameLefts && right == hi - 1) - return; - if (left - lo <= hi - right) { - oquickSort(a, cmp, lo, left); - lo = left + 1; - } - else { - oquickSort(a, cmp, right, hi); - hi = left; - } - } - } - - static void ocquickSort(Comparable[] a, int lo, int hi) { - for (;;) { - if (hi - lo <= INSERTION_SORT_THRESHOLD) { - for (int i = lo + 1; i <= hi; i++) { - Comparable t = a[i]; - int j = i - 1; - while (j >= lo && t.compareTo(a[j]) < 0) { - a[j+1] = a[j]; - --j; - } - a[j+1] = t; - } - return; - } - - int mid = (lo + hi) >>> 1; - if (a[lo].compareTo(a[mid]) > 0) { - Comparable t = a[lo]; a[lo] = a[mid]; a[mid] = t; - } - if (a[mid].compareTo(a[hi]) > 0) { - Comparable t = a[mid]; a[mid] = a[hi]; a[hi] = t; - if (a[lo].compareTo(a[mid]) > 0) { - Comparable u = a[lo]; a[lo] = a[mid]; a[mid] = u; - } - } - Comparable pivot = a[mid]; - int left = lo+1; - int right = hi-1; - boolean sameLefts = true; - for (;;) { - while (pivot.compareTo(a[right]) < 0) - --right; - int c; - while (left < right && (c = pivot.compareTo(a[left])) >= 0) { - if (c != 0) - sameLefts = false; - ++left; - } - if (left < right) { - Comparable t = a[left]; a[left] = a[right]; a[right] = t; - --right; - } - else break; - } - - if (sameLefts && right == hi - 1) - return; - if (left - lo <= hi - right) { - ocquickSort(a, lo, left); - lo = left + 1; - } - else { - ocquickSort(a, right, hi); - hi = left; - } - } - } - static void dquickSort(double[] a, DoubleComparator cmp, int lo, int hi) { for (;;) { @@ -2673,7 +2555,7 @@ class PAS { op.pushUp(par, par.left, par.right); int refork = ((pb & CUMULATE) == 0 && - par.lo == op.origin)? CUMULATE : 0; + par.lo == op.origin) ? CUMULATE : 0; int nextPhase = pb|cb|refork; if (pb == nextPhase || phaseUpdater.compareAndSet(par, pb, nextPhase)) {