@Override public void onCompletion(CountedCompleter<?> caller) { if (node != null) { // Dump buffered elements from this leaf into the sink node.forEach(action); node = null; } else if (spliterator != null) { // Dump elements output from this leaf's pipeline into the sink helper.wrapAndCopyInto(action, spliterator); spliterator = null; } // The completion of this task *and* the dumping of elements // "happens-before" completion of the associated left-most leaf task // of right subtree (if any, which can be this task's right sibling) // ForEachOrderedTask<S, T> leftDescendant = completionMap.remove(this); if (leftDescendant != null) leftDescendant.tryComplete(); }
public final void compute() { CountedCompleter<?> s = this; byte[] a = this.a, w = this.w; // localize all params int b = this.base, n = this.size, wb = this.wbase, g = this.gran; while (n > g) { int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles Relay fc = new Relay(new Merger(s, w, a, wb, h, wb+h, n-h, b, g)); Relay rc = new Relay(new Merger(fc, a, w, b+h, q, b+u, n-u, wb+h, g)); new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork(); new Sorter(rc, a, w, b+h, q, wb+h, g).fork();; Relay bc = new Relay(new Merger(fc, a, w, b, q, b+q, h-q, wb, g)); new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork(); s = new EmptyCompleter(bc); n = q; } DualPivotQuicksort.sort(a, b, b + n - 1); s.tryComplete(); }
public final void compute() { CountedCompleter<?> s = this; int[] a = this.a, w = this.w; // localize all params int b = this.base, n = this.size, wb = this.wbase, g = this.gran; while (n > g) { int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles Relay fc = new Relay(new Merger(s, w, a, wb, h, wb+h, n-h, b, g)); Relay rc = new Relay(new Merger(fc, a, w, b+h, q, b+u, n-u, wb+h, g)); new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork(); new Sorter(rc, a, w, b+h, q, wb+h, g).fork();; Relay bc = new Relay(new Merger(fc, a, w, b, q, b+q, h-q, wb, g)); new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork(); s = new EmptyCompleter(bc); n = q; } DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n); s.tryComplete(); }
public final void compute() { CountedCompleter<?> s = this; float[] a = this.a, w = this.w; // localize all params int b = this.base, n = this.size, wb = this.wbase, g = this.gran; while (n > g) { int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles Relay fc = new Relay(new Merger(s, w, a, wb, h, wb+h, n-h, b, g)); Relay rc = new Relay(new Merger(fc, a, w, b+h, q, b+u, n-u, wb+h, g)); new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork(); new Sorter(rc, a, w, b+h, q, wb+h, g).fork();; Relay bc = new Relay(new Merger(fc, a, w, b, q, b+q, h-q, wb, g)); new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork(); s = new EmptyCompleter(bc); n = q; } DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n); s.tryComplete(); }
public final void compute() { CountedCompleter<?> s = this; double[] a = this.a, w = this.w; // localize all params int b = this.base, n = this.size, wb = this.wbase, g = this.gran; while (n > g) { int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles Relay fc = new Relay(new Merger(s, w, a, wb, h, wb+h, n-h, b, g)); Relay rc = new Relay(new Merger(fc, a, w, b+h, q, b+u, n-u, wb+h, g)); new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork(); new Sorter(rc, a, w, b+h, q, wb+h, g).fork();; Relay bc = new Relay(new Merger(fc, a, w, b, q, b+q, h-q, wb, g)); new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork(); s = new EmptyCompleter(bc); n = q; } DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n); s.tryComplete(); }
public final void compute() { CountedCompleter<?> s = this; Comparator<? super T> c = this.comparator; T[] a = this.a, w = this.w; // localize all params int b = this.base, n = this.size, wb = this.wbase, g = this.gran; while (n > g) { int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles Relay fc = new Relay(new Merger<T>(s, w, a, wb, h, wb+h, n-h, b, g, c)); Relay rc = new Relay(new Merger<T>(fc, a, w, b+h, q, b+u, n-u, wb+h, g, c)); new Sorter<T>(rc, a, w, b+u, n-u, wb+u, g, c).fork(); new Sorter<T>(rc, a, w, b+h, q, wb+h, g, c).fork();; Relay bc = new Relay(new Merger<T>(fc, a, w, b, q, b+q, h-q, wb, g, c)); new Sorter<T>(bc, a, w, b+q, h-q, wb+q, g, c).fork(); s = new EmptyCompleter(bc); n = q; } TimSort.sort(a, b, b + n, c, w, wb, n); s.tryComplete(); }
public final void compute() { CountedCompleter<?> s = this; short[] a = this.a, w = this.w; // localize all params int b = this.base, n = this.size, wb = this.wbase, g = this.gran; while (n > g) { int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles Relay fc = new Relay(new Merger(s, w, a, wb, h, wb+h, n-h, b, g)); Relay rc = new Relay(new Merger(fc, a, w, b+h, q, b+u, n-u, wb+h, g)); new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork(); new Sorter(rc, a, w, b+h, q, wb+h, g).fork();; Relay bc = new Relay(new Merger(fc, a, w, b, q, b+q, h-q, wb, g)); new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork(); s = new EmptyCompleter(bc); n = q; } DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n); s.tryComplete(); }
public final void compute() { CountedCompleter<?> s = this; long[] a = this.a, w = this.w; // localize all params int b = this.base, n = this.size, wb = this.wbase, g = this.gran; while (n > g) { int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles Relay fc = new Relay(new Merger(s, w, a, wb, h, wb+h, n-h, b, g)); Relay rc = new Relay(new Merger(fc, a, w, b+h, q, b+u, n-u, wb+h, g)); new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork(); new Sorter(rc, a, w, b+h, q, wb+h, g).fork();; Relay bc = new Relay(new Merger(fc, a, w, b, q, b+q, h-q, wb, g)); new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork(); s = new EmptyCompleter(bc); n = q; } DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n); s.tryComplete(); }
@Override public final void onCompletion(CountedCompleter<?> caller) { if (!isLeaf()) { Node<P_OUT> result; shortCircuited = leftChild.shortCircuited | rightChild.shortCircuited; if (isOrdered && canceled) { thisNodeSize = 0; result = getEmptyResult(); } else if (isOrdered && leftChild.shortCircuited) { // If taking finished on the left node then // use the left node result thisNodeSize = leftChild.thisNodeSize; result = leftChild.getLocalResult(); } else { thisNodeSize = leftChild.thisNodeSize + rightChild.thisNodeSize; result = merge(); } setLocalResult(result); } completed = true; super.onCompletion(caller); }
public final void compute() { CountedCompleter<?> s = this; Comparator<? super T> c = this.comparator; T[] a = this.a, w = this.w; // localize all params int b = this.base, n = this.size, wb = this.wbase, g = this.gran; while (n > g) { int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles Relay fc = new Relay(new Merger<>(s, w, a, wb, h, wb+h, n-h, b, g, c)); Relay rc = new Relay(new Merger<>(fc, a, w, b+h, q, b+u, n-u, wb+h, g, c)); new Sorter<>(rc, a, w, b+u, n-u, wb+u, g, c).fork(); new Sorter<>(rc, a, w, b+h, q, wb+h, g, c).fork();; Relay bc = new Relay(new Merger<>(fc, a, w, b, q, b+q, h-q, wb, g, c)); new Sorter<>(bc, a, w, b+q, h-q, wb+q, g, c).fork(); s = new EmptyCompleter(bc); n = q; } TimSort.sort(a, b, b + n, c, w, wb, n); s.tryComplete(); }
public final void compute() { CountedCompleter<?> s = this; char[] a = this.a, w = this.w; // localize all params int b = this.base, n = this.size, wb = this.wbase, g = this.gran; while (n > g) { int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles Relay fc = new Relay(new Merger(s, w, a, wb, h, wb+h, n-h, b, g)); Relay rc = new Relay(new Merger(fc, a, w, b+h, q, b+u, n-u, wb+h, g)); new Sorter(rc, a, w, b+u, n-u, wb+u, g).fork(); new Sorter(rc, a, w, b+h, q, wb+h, g).fork();; Relay bc = new Relay(new Merger(fc, a, w, b, q, b+q, h-q, wb, g)); new Sorter(bc, a, w, b+q, h-q, wb+q, g).fork(); s = new EmptyCompleter(bc); n = q; } DualPivotQuicksort.sort(a, b, b + n - 1, w, wb, n); s.tryComplete(); }
public final void onCompletion(CountedCompleter caller) { CCF p = (CCF)getCompleter(); int n = number + rnumber; if (p != null) p.rnumber = n; else number = n; }
@Override public void onCompletion(CountedCompleter<?> caller) { if (op.mustFindFirst) { for (FindTask<P_IN, P_OUT, O> child = leftChild, p = null; child != p; p = child, child = rightChild) { O result = child.getLocalResult(); if (result != null && op.presentPredicate.test(result)) { setLocalResult(result); foundResult(result); break; } } } super.onCompletion(caller); }
@Override public final void onCompletion(CountedCompleter<?> caller) { if (!isLeaf()) { Node<P_OUT> result; thisNodeSize = leftChild.thisNodeSize + rightChild.thisNodeSize; if (canceled) { thisNodeSize = 0; result = getEmptyResult(); } else if (thisNodeSize == 0) result = getEmptyResult(); else if (leftChild.thisNodeSize == 0) result = rightChild.getLocalResult(); else { result = Nodes.conc(op.getOutputShape(), leftChild.getLocalResult(), rightChild.getLocalResult()); } setLocalResult(isRoot() ? doTruncate(result) : result); completed = true; } if (targetSize >= 0 && !isRoot() && isLeftCompleted(targetOffset + targetSize)) cancelLaterNodes(); super.onCompletion(caller); }
Sorter(CountedCompleter<?> par, T[] a, T[] w, int base, int size, int wbase, int gran, Comparator<? super T> comparator) { super(par); this.a = a; this.w = w; this.base = base; this.size = size; this.wbase = wbase; this.gran = gran; this.comparator = comparator; }
Merger(CountedCompleter<?> par, T[] a, T[] w, int lbase, int lsize, int rbase, int rsize, int wbase, int gran, Comparator<? super T> comparator) { super(par); this.a = a; this.w = w; this.lbase = lbase; this.lsize = lsize; this.rbase = rbase; this.rsize = rsize; this.wbase = wbase; this.gran = gran; this.comparator = comparator; }
Merger(CountedCompleter<?> par, byte[] a, byte[] w, int lbase, int lsize, int rbase, int rsize, int wbase, int gran) { super(par); this.a = a; this.w = w; this.lbase = lbase; this.lsize = lsize; this.rbase = rbase; this.rsize = rsize; this.wbase = wbase; this.gran = gran; }
public final void compute() { CountedCompleter p; FailingCCF f = this; int n = number; while (n >= 2) { new RFCCF(f, n - 2).fork(); f = new LFCCF(f, --n); } f.number = n; f.onCompletion(f); if ((p = f.getCompleter()) != null) p.tryComplete(); else f.quietlyComplete(); }
Merger(CountedCompleter<?> par, char[] a, char[] w, int lbase, int lsize, int rbase, int rsize, int wbase, int gran) { super(par); this.a = a; this.w = w; this.lbase = lbase; this.lsize = lsize; this.rbase = rbase; this.rsize = rsize; this.wbase = wbase; this.gran = gran; }
void checkNotDone(CountedCompleter a) { assertFalse(a.isDone()); assertFalse(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); assertFalse(a.isCancelled()); assertNull(a.getException()); assertNull(a.getRawResult()); try { a.get(randomExpiredTimeout(), randomTimeUnit()); shouldThrow(); } catch (TimeoutException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } }
Merger(CountedCompleter<?> par, short[] a, short[] w, int lbase, int lsize, int rbase, int rsize, int wbase, int gran) { super(par); this.a = a; this.w = w; this.lbase = lbase; this.lsize = lsize; this.rbase = rbase; this.rsize = rsize; this.wbase = wbase; this.gran = gran; }
Merger(CountedCompleter<?> par, int[] a, int[] w, int lbase, int lsize, int rbase, int rsize, int wbase, int gran) { super(par); this.a = a; this.w = w; this.lbase = lbase; this.lsize = lsize; this.rbase = rbase; this.rsize = rsize; this.wbase = wbase; this.gran = gran; }
Merger(CountedCompleter<?> par, long[] a, long[] w, int lbase, int lsize, int rbase, int rsize, int wbase, int gran) { super(par); this.a = a; this.w = w; this.lbase = lbase; this.lsize = lsize; this.rbase = rbase; this.rsize = rsize; this.wbase = wbase; this.gran = gran; }
@Override public void onCompletion(CountedCompleter<?> caller) { if (!isLeaf()) { S leftResult = leftChild.getLocalResult(); leftResult.combine(rightChild.getLocalResult()); setLocalResult(leftResult); } // GC spliterator, left and right child super.onCompletion(caller); }
Merger(CountedCompleter<?> par, float[] a, float[] w, int lbase, int lsize, int rbase, int rsize, int wbase, int gran) { super(par); this.a = a; this.w = w; this.lbase = lbase; this.lsize = lsize; this.rbase = rbase; this.rsize = rsize; this.wbase = wbase; this.gran = gran; }