Wraps a ParallelArray instance in map/reduce operation chains.
Constructor and description |
---|
AbstractPAWrapper
(java.lang.Object pa) Creates an instance wrapping the supplied instance of ParallelArray |
Type | Name and description |
---|---|
java.util.Map |
combine(java.lang.Object initialValue, groovy.lang.Closure accumulation) Performs a parallel combine operation. |
java.util.Map |
combineImpl(groovy.lang.Closure initialValue, groovy.lang.Closure accumulation) |
java.util.Map |
combineImpl(java.lang.Object extractKey, java.lang.Object extractValue, groovy.lang.Closure initialValue, groovy.lang.Closure accumulation) |
AbstractPAWrapper |
filter(groovy.lang.Closure cl) Filters concurrently elements in the collection based on the outcome of the supplied function on each of the elements. |
java.lang.Object |
getCollection() Reconstructs a collection from the wrapped ParallelArray instance |
java.util.Map |
groupBy(groovy.lang.Closure cl) Performs parallel groupBy operation. |
AbstractPAWrapper |
map(groovy.lang.Closure cl) Applies concurrently the supplied function to all elements in the collection, returning a collection containing the transformed values. |
T |
max() Finds in parallel the maximum of all values in the collection. |
T |
max(groovy.lang.Closure cl) Finds in parallel the maximum of all values in the collection. |
T |
min() Finds in parallel the minimum of all values in the collection. |
T |
min(groovy.lang.Closure cl) Finds in parallel the minimum of all values in the collection. |
T |
reduce(groovy.lang.Closure cl) Performs a parallel reduce operation. |
T |
reduce(java.lang.Object seed, groovy.lang.Closure cl) Performs a parallel reduce operation. |
int |
size() Size of the collection |
AbstractPAWrapper |
sort(groovy.lang.Closure cl = { it }) Returns a sorted parallel collection If the supplied closure takes two arguments it is used directly as a comparator. |
T |
sum() Summarizes all elements of the collection in parallel using the "plus()" operator of the elements |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Creates an instance wrapping the supplied instance of ParallelArray
Performs a parallel combine operation.
The operation accepts a collection of tuples (two-element lists). The element at position 0 is treated as a key,
while the element at position 1 is considered to be the value.
By running 'combine' on such a collection of tuples, you'll back a map of get items with the same keys (the key is represented by tuple[0])
to be combined into a single element under their common key.
E.g. [[a, b], [c, d], [a, e], [c, f]] will be combined into [a : b+e, c : d+f], while the '+' operation on the values needs to be provided by the user as the accumulation closure.
The keys will be mutually compared using their equals and hashCode methods.
The 'accumulation function' argument needs to specify a function to use for combining (accumulating) the values belonging to the same key.
An 'initial accumulator value' needs to be provided as well. Since the 'combine' method processes items in parallel, the 'initial accumulator value' will be reused multiple times.
Thus the provided value must allow for reuse. It should be either a cloneable or immutable value or a closure returning a fresh initial accumulator each time requested.
Good combinations of accumulator functions and reusable initial values include:
accumulator = {List acc, value -> acc << value} initialValue = []
accumulator = {List acc, value -> acc << value} initialValue = {-> []}*
accumulator = {int sum, int value -> acc + value} initialValue = 0
accumulator = {int sum, int value -> sum + value} initialValue = {-> 0}*
accumulator = {ShoppingCart cart, Item value -> cart.addItem(value)} initialValue = {-> new ShoppingCart()}*
The return type is a map.
E.g. [['he', 1], ['she', 2], ['he', 2], ['me', 1], ['she, 5], ['he', 1] with the initial value provided a 0 will be combined into
['he' : 4, 'she' : 7, 'he', : 2, 'me' : 1]
Please note that the method returns a regular map, not a PAWrapper instance.
You can use the "getParallel()" method on the returned map to turn it into a parallel collection again.
initialValue
- The initial value for an accumulator. Since it will be used repeatedly, it should be either an unmodifiable value, a cloneable instance or a closure returning a fresh initial/empty accumulator each time requestedaccumulator
- A two-argument closure, first argument being the accumulator and second holding the currently processed value. The closure is supposed to returned a modified accumulator after accumulating the value.Filters concurrently elements in the collection based on the outcome of the supplied function on each of the elements.
A
- closure indicating whether to propagate the given element into the filtered collectionReconstructs a collection from the wrapped ParallelArray instance
Performs parallel groupBy operation. After all the elements have been processed, the method returns a map of groups of the original elements. Elements in the same group gave identical results when the supplied closure was invoked on them. Please note that the method returns a regular map, not a PAWrapper instance. You can use the "getParallel()" method on the returned map to turn it into a parallel collection again.
cl
- A single-argument closure returning the value to use for grouping (the key in the resulting map).Applies concurrently the supplied function to all elements in the collection, returning a collection containing the transformed values.
A
- closure calculating a transformed value from the original oneFinds in parallel the maximum of all values in the collection. The implicit comparator is used.
Finds in parallel the maximum of all values in the collection. The supplied comparator is used. If the supplied closure takes two arguments it is used directly as a comparator. If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
cl
- A one or two-argument closureFinds in parallel the minimum of all values in the collection. The implicit comparator is used.
Finds in parallel the minimum of all values in the collection. The supplied comparator is used. If the supplied closure takes two arguments it is used directly as a comparator. If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
cl
- A one or two-argument closurePerforms a parallel reduce operation. It will use the supplied two-argument closure to gradually reduce two elements into one.
cl
- A two-argument closure merging two elements into one. The return value of the closure will replace the original two elements.Performs a parallel reduce operation. It will use the supplied two-argument closure to gradually reduce two elements into one.
cl
- A two-argument closure merging two elements into one. The return value of the closure will replace the original two elements.Size of the collection
Returns a sorted parallel collection If the supplied closure takes two arguments it is used directly as a comparator. If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
cl
- A one or two-argument closureSummarizes all elements of the collection in parallel using the "plus()" operator of the elements
Copyright © 2008–2014 Václav Pech. All Rights Reserved.