Exemplo n.º 1
0
            internal override Spliterator <T> opEvaluateParallelLazy <P_IN>(PipelineHelper <T> helper, Spliterator <P_IN> spliterator)
            {
                long size = helper.ExactOutputSizeIfKnown(spliterator);

                if (size > 0 && spliterator.hasCharacteristics(java.util.Spliterator_Fields.SUBSIZED))
                {
                    return(new StreamSpliterators.SliceSpliterator.OfRef <>(helper.WrapSpliterator(spliterator), Skip, CalcSliceFence(Skip, Limit)));
                }
                else if (!StreamOpFlag.ORDERED.isKnown(helper.StreamAndOpFlags))
                {
                    return(unorderedSkipLimitSpliterator(helper.WrapSpliterator(spliterator), Skip, Limit, size));
                }
                else
                {
                    // @@@ OOMEs will occur for LongStream.longs().filter(i -> true).limit(n)
                    //     regardless of the value of n
                    //     Need to adjust the target size of splitting for the
                    //     SliceTask from say (size / k) to say min(size / k, 1 << 14)
                    //     This will limit the size of the buffers created at the leaf nodes
                    //     cancellation will be more aggressive cancelling later tasks
                    //     if the target slice size has been reached from a given task,
                    //     cancellation should also clear local results if any
                    return((new SliceTask <>(this, helper, spliterator, CastingArray(), Skip, Limit)).invoke().spliterator());
                }
            }
Exemplo n.º 2
0
            internal override Node <T> opEvaluateParallel <P_IN>(PipelineHelper <T> helper, Spliterator <P_IN> spliterator, IntFunction <T[]> generator)
            {
                long size = helper.ExactOutputSizeIfKnown(spliterator);

                if (size > 0 && spliterator.hasCharacteristics(java.util.Spliterator_Fields.SUBSIZED))
                {
                    // Because the pipeline is SIZED the slice spliterator
                    // can be created from the source, this requires matching
                    // to shape of the source, and is potentially more efficient
                    // than creating the slice spliterator from the pipeline
                    // wrapping spliterator
                    Spliterator <P_IN> s = SliceSpliterator(helper.SourceShape, spliterator, Skip, Limit);
                    return(Nodes.Collect(helper, s, Stream_Fields.True, generator));
                }
                else if (!StreamOpFlag.ORDERED.isKnown(helper.StreamAndOpFlags))
                {
                    Spliterator <T> s = unorderedSkipLimitSpliterator(helper.WrapSpliterator(spliterator), Skip, Limit, size);
                    // Collect using this pipeline, which is empty and therefore
                    // can be used with the pipeline wrapping spliterator
                    // Note that we cannot create a slice spliterator from
                    // the source spliterator if the pipeline is not SIZED
                    return(Nodes.Collect(this, s, Stream_Fields.True, generator));
                }
                else
                {
                    return((new SliceTask <>(this, helper, spliterator, generator, Skip, Limit)).invoke());
                }
            }