org.codehaus.gpars

groovyx.gpars.pa
[Groovy] Class AbstractPAWrapper

java.lang.Object
  groovyx.gpars.pa.AbstractPAWrapper

abstract class AbstractPAWrapper

Wraps a ParallelArray instance in map/reduce operation chains.


Property Summary
java.lang.Object pa

The wrapper ParallelArray instance

 
Constructor Summary
AbstractPAWrapper(java.lang.Object pa)

Creates an instance wrapping the supplied instance of ParallelArray

 
Method Summary
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.

java.lang.Object max()

Finds in parallel the maximum of all values in the collection.

java.lang.Object max(groovy.lang.Closure cl)

Finds in parallel the maximum of all values in the collection.

java.lang.Object min()

Finds in parallel the minimum of all values in the collection.

java.lang.Object min(groovy.lang.Closure cl)

Finds in parallel the minimum of all values in the collection.

java.lang.Object reduce(groovy.lang.Closure cl)

Performs a parallel reduce operation.

java.lang.Object 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.

java.lang.Object sum()

Summarizes all elements of the collection in parallel using the "plus()" operator of the elements

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), 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()
 

Property Detail

pa

final java.lang.Object pa
The wrapper ParallelArray instance


 
Constructor Detail

AbstractPAWrapper

AbstractPAWrapper(java.lang.Object pa)
Creates an instance wrapping the supplied instance of ParallelArray


 
Method Detail

combine

java.util.Map combine(java.lang.Object initialValue, groovy.lang.Closure accumulation)
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.
Parameters:
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 requested
accumulator - 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.
Returns:
A map holding the final accumulated values for each unique key in the original collection of tuples.


combineImpl

java.util.Map combineImpl(groovy.lang.Closure initialValue, groovy.lang.Closure accumulation)


combineImpl

java.util.Map combineImpl(java.lang.Object extractKey, java.lang.Object extractValue, groovy.lang.Closure initialValue, groovy.lang.Closure accumulation)


filter

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.
Parameters:
A - closure indicating whether to propagate the given element into the filtered collection
Returns:
A collection holding the allowed values


getCollection

final java.lang.Object getCollection()
Reconstructs a collection from the wrapped ParallelArray instance
Returns:
A collection containing all elements of the wrapped ParallelArray


groupBy

java.util.Map groupBy(groovy.lang.Closure cl)
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.
Parameters:
cl - A single-argument closure returning the value to use for grouping (the key in the resulting map).
Returns:
A map following the Groovy specification for groupBy


map

final AbstractPAWrapper map(groovy.lang.Closure cl)
Applies concurrently the supplied function to all elements in the collection, returning a collection containing the transformed values.
Parameters:
A - closure calculating a transformed value from the original one
Returns:
A collection holding the new values


max

final java.lang.Object max()
Finds in parallel the maximum of all values in the collection. The implicit comparator is used.
Returns:
The maximum element of the collection


max

final java.lang.Object max(groovy.lang.Closure cl)
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.
Parameters:
cl - A one or two-argument closure
Returns:
The maximum element of the collection


min

final java.lang.Object min()
Finds in parallel the minimum of all values in the collection. The implicit comparator is used.
Returns:
The minimum element of the collection


min

final java.lang.Object min(groovy.lang.Closure cl)
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.
Parameters:
cl - A one or two-argument closure
Returns:
The minimum element of the collection


reduce

final java.lang.Object reduce(groovy.lang.Closure cl)
Performs a parallel reduce operation. It will use the supplied two-argument closure to gradually reduce two elements into one.
Parameters:
cl - A two-argument closure merging two elements into one. The return value of the closure will replace the original two elements.
Returns:
The product of reduction


reduce

final java.lang.Object reduce(java.lang.Object seed, groovy.lang.Closure cl)
Performs a parallel reduce operation. It will use the supplied two-argument closure to gradually reduce two elements into one.
Parameters:
cl - A two-argument closure merging two elements into one. The return value of the closure will replace the original two elements.
Returns:
The product of reduction


size

final int size()
Size of the collection
Returns:
The number of elements in the collection


sort

final 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. 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.
Parameters:
cl - A one or two-argument closure
Returns:
A sorted collection holding all the elements


sum

final java.lang.Object sum()
Summarizes all elements of the collection in parallel using the "plus()" operator of the elements
Returns:
The summary od all elements in the collection


 

Copyright © 2008–2013 Václav Pech. All Rights Reserved.