Stream.unordered()
Paul Sandoz
paul.sandoz at oracle.com
Mon Nov 5 07:49:36 PST 2012
HI,
See attached for a patch that adds Stream.unordered().
This method will clear the encounter order flag. When this flag is cleared certain downstream stateful operations evaluated in parallel may choose to apply algorithms that do not preserve encounter order.
Such algorithms may be more efficient than order preserving algorithms, although i would say that one should not presume this to be a general assumption and has to be taken on a case by case basis.
One such example is obtaining unique elements.
When encounter order is to be preserved it might be required to merge the linked hash sets produced at the leaves of the computation tree. That merging has a cost, i suspect it is rather tricky to write a parallel set merge algorithm, so a naive implementation would just take the set on the left hand side of a tree and merge with set on the right hand side using Set.addAll.
When encounter order need not be preserved one can stuff elements as and when they are produced into a shared ConcurrentHashMap.
Paul.
-------------- next part --------------
More information about the lambda-dev
mailing list