@Override protected TakeWhileTask<P_IN, P_OUT> makeChild(Spliterator<P_IN> spliterator) { return new TakeWhileTask<>(this, spliterator); }
@Override protected final Node<P_OUT> doLeaf() { Node.Builder<P_OUT> builder = helper.makeNodeBuilder(-1, generator); Sink<P_OUT> s = op.opWrapSink(helper.getStreamAndOpFlags(), builder); if (shortCircuited = helper.copyIntoWithCancel(helper.wrapSink(s), spliterator)) { // Cancel later nodes if the predicate returned false // during traversal cancelLaterNodes(); } Node<P_OUT> node = builder.build(); thisNodeSize = node.count(); return node; }
@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); }
@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); }
Node<P_OUT> merge() { if (leftChild.thisNodeSize == 0) { // If the left node size is 0 then // use the right node result return rightChild.getLocalResult(); } else if (rightChild.thisNodeSize == 0) { // If the right node size is 0 then // use the left node result return leftChild.getLocalResult(); } else { // Combine the left and right nodes return Nodes.conc(op.getOutputShape(), leftChild.getLocalResult(), rightChild.getLocalResult()); } }
Node<P_OUT> merge() { if (leftChild.thisNodeSize == 0) { // If the left node size is 0 then // use the right node result return rightChild.getLocalResult(); } else if (rightChild.thisNodeSize == 0) { // If the right node size is 0 then // use the left node result return leftChild.getLocalResult(); } else { // Combine the left and right nodes return Nodes.conc(op.getOutputShape(), leftChild.getLocalResult(), rightChild.getLocalResult()); } }
@Override protected final Node<P_OUT> doLeaf() { Node.Builder<P_OUT> builder = helper.makeNodeBuilder(-1, generator); Sink<P_OUT> s = op.opWrapSink(helper.getStreamAndOpFlags(), builder); if (shortCircuited = helper.copyIntoWithCancel(helper.wrapSink(s), spliterator)) { // Cancel later nodes if the predicate returned false // during traversal cancelLaterNodes(); } Node<P_OUT> node = builder.build(); thisNodeSize = node.count(); return node; }
@Override protected TakeWhileTask<P_IN, P_OUT> makeChild(Spliterator<P_IN> spliterator) { return new TakeWhileTask<>(this, spliterator); }
@Override protected void cancel() { super.cancel(); if (isOrdered && completed) // If the task is completed then clear the result, if any // to aid GC setLocalResult(getEmptyResult()); } }
@Override protected void cancel() { super.cancel(); if (isOrdered && completed) // If the task is completed then clear the result, if any // to aid GC setLocalResult(getEmptyResult()); } }