30 |
|
System.out.println("Usage: java BoxedLongSort threads n reps"); |
31 |
|
return; |
32 |
|
} |
33 |
< |
ForkJoinPool pool = procs == 0? new ForkJoinPool() : |
33 |
> |
ForkJoinPool pool = procs == 0? new ForkJoinPool() : |
34 |
|
new ForkJoinPool(procs); |
35 |
< |
|
35 |
> |
|
36 |
|
Long[] a = new Long[n]; |
37 |
|
seqRandomFill(a, 0, n); |
38 |
|
|
80 |
|
} |
81 |
|
|
82 |
|
static final class Sorter extends RecursiveAction { |
83 |
< |
final Long[] a; |
83 |
> |
final Long[] a; |
84 |
|
final Long[] w; |
85 |
< |
final int origin; |
85 |
> |
final int origin; |
86 |
|
final int n; |
87 |
|
Sorter(Long[] a, Long[] w, int origin, int n) { |
88 |
|
this.a = a; this.w = w; this.origin = origin; this.n = n; |
111 |
|
} |
112 |
|
} |
113 |
|
} |
114 |
< |
|
114 |
> |
|
115 |
|
static final class SubSorter extends RecursiveAction { |
116 |
|
final Sorter left; |
117 |
|
final Sorter right; |
145 |
|
* and finding index of right closest to split point. |
146 |
|
* Uses left-spine decomposition to generate all |
147 |
|
* merge tasks before bottomming out at base case. |
148 |
< |
* |
148 |
> |
* |
149 |
|
*/ |
150 |
|
public final void compute() { |
151 |
|
Merger rights = null; |
169 |
|
nleft = lh; |
170 |
|
nright = rh; |
171 |
|
} |
172 |
< |
|
172 |
> |
|
173 |
|
merge(nleft, nright); |
174 |
< |
if (rights != null) |
174 |
> |
if (rights != null) |
175 |
|
collectRights(rights); |
176 |
< |
|
176 |
> |
|
177 |
|
} |
178 |
|
|
179 |
|
final void merge(int nleft, int nright) { |
210 |
|
int n = a.length; |
211 |
|
for (int i = 0; i < n - 1; i++) { |
212 |
|
if (a[i] > a[i+1]) { |
213 |
< |
throw new Error("Unsorted at " + i + ": " + |
213 |
> |
throw new Error("Unsorted at " + i + ": " + |
214 |
|
a[i] + " / " + a[i+1]); |
215 |
|
} |
216 |
|
} |