public class ParallelArray<T> extends AbstractParallelAnyArray.OUPap<T> implements java.lang.Iterable<T>
A ParallelArray maintains a ForkJoinPool
and an
array in order to provide parallel aggregate operations. The main
operations are to apply some procedure to each element, to
map each element to a new element, to replace
each element, to select a subset of elements based on
matching a predicate or ranges of indices, and to reduce
all elements into a single value such as a sum.
A ParallelArray is constructed by allocating, using, or copying
an array, using one of the static factory methods create(int, java.lang.Class<? super T>, jsr166y.ForkJoinPool)
,
createEmpty(int, java.lang.Class<? super T>, jsr166y.ForkJoinPool)
, createUsingHandoff(T[], jsr166y.ForkJoinPool)
and createFromCopy(T[], jsr166y.ForkJoinPool)
. Upon construction, the encapsulated array managed
by the ParallelArray must not be shared between threads without
external synchronization. In particular, as is the case with any
array, access by another thread of an element of a ParallelArray
while another operation is in progress has undefined effects.
The ForkJoinPool used to construct a ParallelArray can be
shared safely by other threads (and used in other
ParallelArrays). To avoid the overhead associated with creating
multiple executors, it is often a good idea to use the defaultExecutor()
across all ParallelArrays. However, you might
choose to use different ones for the sake of controlling processor
usage, isolating faults, and/or ensuring progress.
A ParallelArray is not a List. It relies on random access across
array elements to support efficient parallel operations. However,
a ParallelArray can be viewed and manipulated as a List, via method
asList()
. The asList
view allows
incremental insertion and modification of elements while setting up
a ParallelArray, generally before using it for parallel
operations. Similarly, the list view may be useful when accessing
the results of computations in sequential contexts. A
ParallelArray may also be created using the elements of any other
Collection, by constructing from the array returned by the
Collection's toArray
method. The effects of mutative
asList
operations may also be achieved directly using
method setLimit(int)
along with element-by-element access
methods get(int)
and set(int, T)
.
While ParallelArrays can be based on any kind of an object
array, including "boxed" types such as Long, parallel operations on
scalar "unboxed" type are likely to be substantially more
efficient. For this reason, classes ParallelLongArray
and
ParallelDoubleArray
are also supplied, and designed to
smoothly interoperate with ParallelArrays. You should also use a
ParallelLongArray for processing other integral scalar data
(int
, short
, etc). And similarly use a
ParallelDoubleArray for float
data. (Further
specializations for these other types would add clutter without
significantly improving performance beyond that of the Long and
Double versions.)
Most usages of ParallelArray involve sets of operations prefixed
with range bounds, filters, and mappings (including mappings that
combine elements from other ParallelArrays), using
withBounds
, withFilter
, and withMapping
,
respectively. For example,
aParallelArray.withFilter(aPredicate).all()
creates a new
ParallelArray containing only those elements matching the
predicate. And for ParallelLongArrays a, b, and c,
a.withMapping(CommonOps.longAdder(),b).withMapping(CommonOps.longAdder(),c).min()
returns the minimum value of a[i]+b[i]+c[i] for all i. As
illustrated below, a mapping often represents accessing
some field or invoking some method of an element. These versions
are typically more efficient than performing selections, then
mappings, then other operations in multiple (parallel) steps. The
basic ideas and usages of filtering and mapping are similar to
those in database query systems such as SQL, but take a more
restrictive form. Series of filter and mapping prefixes may each
be cascaded, but all filter prefixes must precede all mapping
prefixes, to ensure efficient execution in a single parallel step.
In cases of combined mapping expressions, this rule is only
dynamically enforced. For example, pa.withMapping(op,
pb.withFilter(f))
will compile but throw an exception upon
execution because the filter precedes the mapping.
While series of filters and mappings are allowed, it is
usually more efficient to combine them into single filters or
mappings when possible. For example
pa.withMapping(addOne).withMapping(addOne)
is generally
less efficient than pa.withMapping(addTwo)
. Methods
withIndexedFilter
and withIndexedMapping
may be
useful when combining such expressions.
This class includes some reductions, such as min
, that
are commonly useful for most element types, as well as a combined
version, summary
, that computes all of them in a single
parallel step, which is normally more efficient than computing each
in turn.
The methods in this class are designed to perform efficiently with both large and small pools, even with single-thread pools on uniprocessors. However, there is some overhead in parallelizing operations, so short computations on small arrays might not execute faster than sequential versions, and might even be slower.
Sample usages.
The main difference between programming with plain arrays and
programming with aggregates is that you must separately define each
of the component functions on elements. For example, the following
returns the maximum Grade Point Average across all senior students,
given a (fictional) Student
class:
import static Ops.*; class StudentStatistics { ParallelArray<Student> students = ... // ... public double getMaxSeniorGpa() { return students.withFilter(isSenior).withMapping(gpaField).max(); } // helpers: static final class IsSenior implements Predicate<Student> { public boolean op(Student s) { return s.credits > 90; } } static final IsSenior isSenior = new IsSenior(); static final class GpaField implements ObjectToDouble<Student> { public double op(Student s) { return s.gpa; } } static final GpaField gpaField = new GpaField(); }
Modifier and Type | Class and Description |
---|---|
(package private) class |
ParallelArray.AsList |
(package private) class |
ParallelArray.ListIter |
(package private) static class |
ParallelArray.ParallelArrayIterator<T> |
static interface |
ParallelArray.SummaryStatistics<T>
Summary statistics for a possibly bounded, filtered, and/or
mapped ParallelArray.
|
AbstractParallelAnyArray.AndPredicate<T>, AbstractParallelAnyArray.DDCPap, AbstractParallelAnyArray.DDMPap, AbstractParallelAnyArray.DFDCPap, AbstractParallelAnyArray.DFDMPap, AbstractParallelAnyArray.DFLCPap, AbstractParallelAnyArray.DFLMPap, AbstractParallelAnyArray.DFOCPap<U>, AbstractParallelAnyArray.DFOMPap<U>, AbstractParallelAnyArray.DFPap, AbstractParallelAnyArray.DLCPap, AbstractParallelAnyArray.DLMPap, AbstractParallelAnyArray.DOCPap<U>, AbstractParallelAnyArray.DOMPap<U>, AbstractParallelAnyArray.DPap, AbstractParallelAnyArray.DRDCPap, AbstractParallelAnyArray.DRDMPap, AbstractParallelAnyArray.DRLCPap, AbstractParallelAnyArray.DRLMPap, AbstractParallelAnyArray.DROCPap<U>, AbstractParallelAnyArray.DROMPap<U>, AbstractParallelAnyArray.DRPap, AbstractParallelAnyArray.DUDCPap, AbstractParallelAnyArray.DUDMPap, AbstractParallelAnyArray.DULCPap, AbstractParallelAnyArray.DULMPap, AbstractParallelAnyArray.DUOCPap<U>, AbstractParallelAnyArray.DUOMPap<U>, AbstractParallelAnyArray.DUPap, AbstractParallelAnyArray.FilteredAsDoubleIterator, AbstractParallelAnyArray.FilteredAsLongIterator, AbstractParallelAnyArray.FilteredIterator<U>, AbstractParallelAnyArray.LDCPap, AbstractParallelAnyArray.LDMPap, AbstractParallelAnyArray.LFDCPap, AbstractParallelAnyArray.LFDMPap, AbstractParallelAnyArray.LFLCPap, AbstractParallelAnyArray.LFLMPap, AbstractParallelAnyArray.LFOCPap<U>, AbstractParallelAnyArray.LFOMPap<U>, AbstractParallelAnyArray.LFPap, AbstractParallelAnyArray.LLCPap, AbstractParallelAnyArray.LLMPap, AbstractParallelAnyArray.LOCPap<U>, AbstractParallelAnyArray.LOMPap<U>, AbstractParallelAnyArray.LPap, AbstractParallelAnyArray.LRDCPap, AbstractParallelAnyArray.LRDMPap, AbstractParallelAnyArray.LRLCPap, AbstractParallelAnyArray.LRLMPap, AbstractParallelAnyArray.LROCPap<U>, AbstractParallelAnyArray.LROMPap<U>, AbstractParallelAnyArray.LRPap, AbstractParallelAnyArray.LUDCPap, AbstractParallelAnyArray.LUDMPap, AbstractParallelAnyArray.LULCPap, AbstractParallelAnyArray.LULMPap, AbstractParallelAnyArray.LUOCPap<U>, AbstractParallelAnyArray.LUOMPap<U>, AbstractParallelAnyArray.LUPap, AbstractParallelAnyArray.ODCPap<T>, AbstractParallelAnyArray.ODMPap<T>, AbstractParallelAnyArray.OFDCPap<T>, AbstractParallelAnyArray.OFDMPap<T>, AbstractParallelAnyArray.OFLCPap<T>, AbstractParallelAnyArray.OFLMPap<T>, AbstractParallelAnyArray.OFOCPap<T,U>, AbstractParallelAnyArray.OFOMPap<T,U>, AbstractParallelAnyArray.OFPap<T>, AbstractParallelAnyArray.OLCPap<T>, AbstractParallelAnyArray.OLMPap<T>, AbstractParallelAnyArray.OOCPap<T,U>, AbstractParallelAnyArray.OOMPap<T,U>, AbstractParallelAnyArray.OPap<T>, AbstractParallelAnyArray.ORDCPap<T>, AbstractParallelAnyArray.ORDMPap<T>, AbstractParallelAnyArray.ORLCPap<T>, AbstractParallelAnyArray.ORLMPap<T>, AbstractParallelAnyArray.OROCPap<T,U>, AbstractParallelAnyArray.OROMPap<T,U>, AbstractParallelAnyArray.ORPap<T>, AbstractParallelAnyArray.OUDCPap<T>, AbstractParallelAnyArray.OUDMPap<T>, AbstractParallelAnyArray.OULCPap<T>, AbstractParallelAnyArray.OULMPap<T>, AbstractParallelAnyArray.OUOCPap<T,U>, AbstractParallelAnyArray.OUOMPap<T,U>, AbstractParallelAnyArray.OUPap<T>, AbstractParallelAnyArray.Sequentially<U>, AbstractParallelAnyArray.SequentiallyAsDouble, AbstractParallelAnyArray.SequentiallyAsLong, AbstractParallelAnyArray.UnfilteredAsDoubleIterator, AbstractParallelAnyArray.UnfilteredAsLongIterator, AbstractParallelAnyArray.UnfilteredIterator<U>
Modifier and Type | Field and Description |
---|---|
(package private) ParallelArray.AsList |
listView
Lazily constructed list view
|
array
ex, fence, origin, threshold
Modifier | Constructor and Description |
---|---|
(package private) |
ParallelArray(jsr166y.ForkJoinPool executor,
T[] array)
Trusted internal version of protected constructor.
|
protected |
ParallelArray(jsr166y.ForkJoinPool executor,
T[] array,
int limit)
Constructor for use by subclasses to create a new ParallelArray
using the given executor, and initially using the supplied
array, with effective size bound by the given limit.
|
Modifier and Type | Method and Description |
---|---|
<V> ParallelArray<T> |
addAll(ParallelArrayWithMapping<V,T> other)
Appends all (possibly bounded, filtered, or mapped) elements of
the given ParallelArray, resizing and/or reallocating this
array if necessary.
|
ParallelArray<T> |
addAll(T[] other)
Equivalent to
asList().addAll but specialized for array
arguments and likely to be more efficient. |
ParallelArray<T> |
all()
Returns a new ParallelArray holding all elements.
|
ParallelArray<T> |
all(java.lang.Class<? super T> elementType)
Returns a new ParallelArray with the given element type holding
all elements.
|
ParallelArray<T> |
allNonidenticalElements()
Returns a new ParallelArray containing only the non-null unique
elements of this array (that is, without any duplicates), using
reference identity to test for duplication.
|
ParallelArray<T> |
allUniqueElements()
Returns a new ParallelArray containing only the non-null unique
elements of this array (that is, without any duplicates), using
each element's
equals method to test for duplication. |
(package private) void |
appendElement(T e) |
void |
apply(Ops.Procedure<? super T> procedure)
Applies the given procedure to elements.
|
java.util.List<T> |
asList()
Returns a view of this ParallelArray as a List.
|
int |
binarySearch(T target)
Assuming this array is sorted, returns the index of an element
equal to given target, or -1 if not present.
|
int |
binarySearch(T target,
java.util.Comparator<? super T> comparator)
Assuming this array is sorted with respect to the given
comparator, returns the index of an element equal to given
target, or -1 if not present.
|
static <T> ParallelArray<T> |
create(int size,
java.lang.Class<? super T> elementType,
jsr166y.ForkJoinPool executor)
Creates a new ParallelArray using the given executor and
an array of the given size constructed using the
indicated base element type.
|
static <T> ParallelArray<T> |
createEmpty(int size,
java.lang.Class<? super T> elementType,
jsr166y.ForkJoinPool executor)
Creates a new ParallelArray using the given executor and an
array of the given size constructed using the indicated base
element type, but with an initial effective size of zero,
enabling incremental insertion via
asList()
operations. |
static <T> ParallelArray<T> |
createFromCopy(int size,
T[] source,
jsr166y.ForkJoinPool executor)
Creates a new ParallelArray using an array of the given size,
initially holding copies of the given source truncated or
padded with nulls to obtain the specified length.
|
static <T> ParallelArray<T> |
createFromCopy(T[] source,
jsr166y.ForkJoinPool executor)
Creates a new ParallelArray using the given executor and
initially holding copies of the given
source elements.
|
static <T> ParallelArray<T> |
createUsingHandoff(T[] handoff,
jsr166y.ForkJoinPool executor)
Creates a new ParallelArray initially using the given array and
executor.
|
ParallelArray<T> |
cumulate(Ops.Reducer<T> reducer,
T base)
Replaces each element with the running cumulation of applying
the given reducer.
|
static jsr166y.ForkJoinPool |
defaultExecutor()
Returns a common default executor for use in ParallelArrays.
|
T |
get(int i)
Returns the element of the array at the given index.
|
T[] |
getArray()
Returns the underlying array used for computations.
|
jsr166y.ForkJoinPool |
getExecutor()
Returns the executor used for computations.
|
<U,V> boolean |
hasAllEqualElements(ParallelArrayWithMapping<U,V> other)
Returns true if all elements at the same relative positions
of this and other array are equal.
|
<U,V> boolean |
hasAllIdenticalElements(ParallelArrayWithMapping<U,V> other)
Returns true if all elements at the same relative positions
of this and other array are identical.
|
int |
indexOf(T target)
Returns the index of some element equal to given target,
or -1 if not present.
|
(package private) void |
insertElementAt(int index,
T e) |
(package private) void |
insertSlotsAt(int index,
int len)
Makes len slots available at index.
|
java.util.Iterator<T> |
iterator()
Returns an iterator stepping through each element of the array
up to the current limit.
|
T |
max()
Returns the maximum element, or null if empty,
assuming that all elements are Comparables.
|
T |
max(java.util.Comparator<? super T> comparator)
Returns the maximum element, or null if empty.
|
T |
min()
Returns the minimum element, or null if empty,
assuming that all elements are Comparables.
|
T |
min(java.util.Comparator<? super T> comparator)
Returns the minimum element, or null if empty.
|
T |
precumulate(Ops.Reducer<T> reducer,
T base)
Replaces each element with the cumulation of applying the given
reducer to all previous values, and returns the total
reduction.
|
T |
reduce(Ops.Reducer<T> reducer,
T base)
Returns reduction of elements.
|
ParallelArray<T> |
removeAll(Ops.Predicate<? super T> selector)
Removes from the array all elements for which the given
selector holds.
|
ParallelArray<T> |
removeConsecutiveDuplicates()
Removes consecutive elements that are equal (or null),
shifting others leftward, and possibly decreasing size.
|
ParallelArray<T> |
removeNulls()
Removes null elements, shifting others leftward, and possibly
decreasing size.
|
(package private) void |
removeSlotAt(int index) |
(package private) void |
removeSlotsAt(int fromIndex,
int toIndex) |
(package private) void |
replaceElementsWith(T[] a) |
ParallelArray<T> |
replaceWithGeneratedValue(Ops.Generator<? extends T> generator)
Replaces elements with the results of applying the given
generator.
|
ParallelArray<T> |
replaceWithMappedIndex(Ops.IntAndObjectToObject<? super T,? extends T> op)
Replaces elements with the results of applying the given
mapping to each index and current element value.
|
ParallelArray<T> |
replaceWithMappedIndex(Ops.IntToObject<? extends T> op)
Replaces elements with the results of applying the given
mapping to their indices.
|
<V,W> ParallelArray<T> |
replaceWithMapping(Ops.BinaryOp<? super T,? super V,? extends T> combiner,
ParallelArrayWithMapping<W,V> other)
Replaces elements with results of applying
op(thisElement, otherElement) . |
ParallelArray<T> |
replaceWithMapping(Ops.BinaryOp<T,T,T> combiner,
T[] other)
Replaces elements with results of applying
op(thisElement, otherElement) . |
ParallelArray<T> |
replaceWithMapping(Ops.Op<? super T,? extends T> op)
Replaces elements with the results of applying the given transform
to their current values.
|
ParallelArray<T> |
replaceWithValue(T value)
Replaces elements with the given value.
|
(package private) void |
resizeArray(int newCap) |
(package private) int |
seqIndexOf(java.lang.Object target) |
(package private) int |
seqLastIndexOf(java.lang.Object target) |
void |
set(int i,
T x)
Sets the element of the array at the given index to the given value.
|
void |
setLimit(int newLimit)
Ensures that the underlying array can be accessed up to the
given upper bound, reallocating and copying the underlying
array to expand if necessary.
|
int |
size()
Returns the effective size of the underlying array.
|
ParallelArray<T> |
sort()
Sorts the array, assuming all elements are Comparable.
|
ParallelArray<T> |
sort(java.util.Comparator<? super T> comparator)
Sorts the array.
|
ParallelArray.SummaryStatistics<T> |
summary()
Returns summary statistics, assuming that all elements are
Comparables.
|
ParallelArray.SummaryStatistics<T> |
summary(java.util.Comparator<? super T> comparator)
Returns summary statistics, using the given comparator
to locate minimum and maximum elements.
|
java.lang.String |
toString()
Equivalent to
asList().toString() . |
ParallelArrayWithBounds<T> |
withBounds(int firstIndex,
int upperBound)
Returns an operation prefix that causes a method to
operate only on the elements of the array between
firstIndex (inclusive) and upperBound (exclusive).
|
<V,W> ParallelArrayWithFilter<T> |
withFilter(Ops.BinaryPredicate<? super T,? super V> selector,
ParallelArrayWithMapping<W,V> other)
Returns an operation prefix that causes a method to operate
only on elements for which the given binary selector returns
true.
|
ParallelArrayWithFilter<T> |
withFilter(Ops.Predicate<? super T> selector)
Returns an operation prefix that causes a method to operate
only on the elements of the array for which the given selector
returns true.
|
ParallelArrayWithFilter<T> |
withIndexedFilter(Ops.IntAndObjectPredicate<? super T> selector)
Returns an operation prefix that causes a method to operate
only on elements for which the given indexed selector returns
true.
|
ParallelArrayWithDoubleMapping<T> |
withIndexedMapping(Ops.IntAndObjectToDouble<? super T> mapper)
Returns an operation prefix that causes a method to operate on
mappings of this array using the given mapper that accepts as
arguments an element's current index and value, and produces a
new value.
|
ParallelArrayWithLongMapping<T> |
withIndexedMapping(Ops.IntAndObjectToLong<? super T> mapper)
Returns an operation prefix that causes a method to operate on
mappings of this array using the given mapper that accepts as
arguments an element's current index and value, and produces a
new value.
|
<U> ParallelArrayWithMapping<T,U> |
withIndexedMapping(Ops.IntAndObjectToObject<? super T,? extends U> mapper)
Returns an operation prefix that causes a method to operate on
mappings of this array using the given mapper that accepts as
arguments an element's current index and value, and produces a
new value.
|
<U,V,W> ParallelArrayWithMapping<T,V> |
withMapping(Ops.BinaryOp<? super T,? super U,? extends V> combiner,
ParallelArrayWithMapping<W,U> other)
Returns an operation prefix that causes a method to operate
on binary mappings of this array and the other array.
|
ParallelArrayWithDoubleMapping<T> |
withMapping(Ops.ObjectAndDoubleToDouble<? super T> combiner,
ParallelDoubleArrayWithDoubleMapping other)
Returns an operation prefix that causes a method to operate
on binary mappings of this array and the other array.
|
ParallelArrayWithLongMapping<T> |
withMapping(Ops.ObjectAndDoubleToLong<? super T> combiner,
ParallelDoubleArrayWithDoubleMapping other)
Returns an operation prefix that causes a method to operate
on binary mappings of this array and the other array.
|
<V> ParallelArrayWithMapping<T,V> |
withMapping(Ops.ObjectAndDoubleToObject<? super T,? extends V> combiner,
ParallelDoubleArrayWithDoubleMapping other)
Returns an operation prefix that causes a method to operate
on binary mappings of this array and the other array.
|
ParallelArrayWithDoubleMapping<T> |
withMapping(Ops.ObjectAndLongToDouble<? super T> combiner,
ParallelLongArrayWithLongMapping other)
Returns an operation prefix that causes a method to operate
on binary mappings of this array and the other array.
|
ParallelArrayWithLongMapping<T> |
withMapping(Ops.ObjectAndLongToLong<? super T> combiner,
ParallelLongArrayWithLongMapping other)
Returns an operation prefix that causes a method to operate
on binary mappings of this array and the other array.
|
<V> ParallelArrayWithMapping<T,V> |
withMapping(Ops.ObjectAndLongToObject<? super T,? extends V> combiner,
ParallelLongArrayWithLongMapping other)
Returns an operation prefix that causes a method to operate
on binary mappings of this array and the other array.
|
<U,W> ParallelArrayWithDoubleMapping<T> |
withMapping(Ops.ObjectAndObjectToDouble<? super T,? super U> combiner,
ParallelArrayWithMapping<W,U> other)
Returns an operation prefix that causes a method to operate
on binary mappings of this array and the other array.
|
<U,W> ParallelArrayWithLongMapping<T> |
withMapping(Ops.ObjectAndObjectToLong<? super T,? super U> combiner,
ParallelArrayWithMapping<W,U> other)
Returns an operation prefix that causes a method to operate
on binary mappings of this array and the other array.
|
ParallelArrayWithDoubleMapping<T> |
withMapping(Ops.ObjectToDouble<? super T> op)
Returns an operation prefix that causes a method to operate
on mapped elements of the array using the given op.
|
ParallelArrayWithLongMapping<T> |
withMapping(Ops.ObjectToLong<? super T> op)
Returns an operation prefix that causes a method to operate
on mapped elements of the array using the given op.
|
<U> ParallelArrayWithMapping<T,U> |
withMapping(Ops.Op<? super T,? extends U> op)
Returns an operation prefix that causes a method to operate
on mapped elements of the array using the given op.
|
leafApply, leafBinaryIndexMap, leafCombineInPlace, leafCombineInPlace, leafFill, leafGenerate, leafIndexMap, leafReduce, leafTransform
leafTransfer, leafTransferByIndex, oget
any, sequentially
dget, leafMoveByIndex, leafMoveSelected, lget, ogetArray
allDoubles, allLongs, allObjects, anyIndex, boundsCheck, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedOp, compoundIndexedSelector, compoundIndexedSelector, compoundIndexedSelector, compoundIndexedSelector, compoundIndexedSelector, compoundIndexedSelector, compoundIndexedSelector, compoundIndexedSelector, compoundIndexedSelector, computeThreshold, dgetArray, getThreshold, hasFilter, hasMap, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedMapper, indexedSelector, indexedSelector, indexedSelector, isEmpty, isSelected, leafApply, leafApply, leafBinaryIndexMap, leafBinaryIndexMap, leafCombineInPlace, leafCombineInPlace, leafCombineInPlace, leafCombineInPlace, leafFill, leafFill, leafGenerate, leafGenerate, leafIndexMap, leafIndexMap, leafIndexSelected, leafReduce, leafReduce, leafTransfer, leafTransfer, leafTransferByIndex, leafTransferByIndex, leafTransform, leafTransform, lgetArray
ParallelArray.AsList listView
protected ParallelArray(jsr166y.ForkJoinPool executor, T[] array, int limit)
create(int, java.lang.Class<? super T>, jsr166y.ForkJoinPool)
,
createEmpty(int, java.lang.Class<? super T>, jsr166y.ForkJoinPool)
, createUsingHandoff(T[], jsr166y.ForkJoinPool)
or createFromCopy(T[], jsr166y.ForkJoinPool)
.executor
- the executorarray
- the arraylimit
- the upper bound limitParallelArray(jsr166y.ForkJoinPool executor, T[] array)
public static jsr166y.ForkJoinPool defaultExecutor()
public static <T> ParallelArray<T> create(int size, java.lang.Class<? super T> elementType, jsr166y.ForkJoinPool executor)
size
- the array sizeelementType
- the type of the elementsexecutor
- the executorpublic static <T> ParallelArray<T> createUsingHandoff(T[] handoff, jsr166y.ForkJoinPool executor)
handoff
- the arrayexecutor
- the executorpublic static <T> ParallelArray<T> createFromCopy(T[] source, jsr166y.ForkJoinPool executor)
source
- the source of initial elementsexecutor
- the executorpublic static <T> ParallelArray<T> createFromCopy(int size, T[] source, jsr166y.ForkJoinPool executor)
source
- the source of initial elementssize
- the array sizeexecutor
- the executorpublic static <T> ParallelArray<T> createEmpty(int size, java.lang.Class<? super T> elementType, jsr166y.ForkJoinPool executor)
asList()
operations.size
- the array sizeelementType
- the type of the elementsexecutor
- the executorpublic jsr166y.ForkJoinPool getExecutor()
public void apply(Ops.Procedure<? super T> procedure)
apply
in class ParallelArrayWithMapping<T,T>
procedure
- the procedurepublic T reduce(Ops.Reducer<T> reducer, T base)
reduce
in class ParallelArrayWithMapping<T,T>
reducer
- the reducerbase
- the result for an empty arraypublic ParallelArray<T> all()
all
in class ParallelArrayWithMapping<T,T>
public ParallelArray<T> all(java.lang.Class<? super T> elementType)
all
in class ParallelArrayWithMapping<T,T>
elementType
- the type of the elementspublic ParallelArray<T> replaceWithMapping(Ops.Op<? super T,? extends T> op)
replaceWithMapping
in class ParallelArrayWithFilter<T>
op
- the oppublic ParallelArray<T> replaceWithMappedIndex(Ops.IntToObject<? extends T> op)
replaceWithMappedIndex
in class ParallelArrayWithFilter<T>
op
- the oppublic ParallelArray<T> replaceWithMappedIndex(Ops.IntAndObjectToObject<? super T,? extends T> op)
replaceWithMappedIndex
in class ParallelArrayWithFilter<T>
op
- the oppublic ParallelArray<T> replaceWithGeneratedValue(Ops.Generator<? extends T> generator)
replaceWithGeneratedValue
in class ParallelArrayWithFilter<T>
generator
- the generatorpublic ParallelArray<T> replaceWithValue(T value)
replaceWithValue
in class ParallelArrayWithFilter<T>
value
- the valuepublic <V,W> ParallelArray<T> replaceWithMapping(Ops.BinaryOp<? super T,? super V,? extends T> combiner, ParallelArrayWithMapping<W,V> other)
op(thisElement, otherElement)
.replaceWithMapping
in class ParallelArrayWithFilter<T>
other
- the other arraycombiner
- the combinerpublic ParallelArray<T> replaceWithMapping(Ops.BinaryOp<T,T,T> combiner, T[] other)
op(thisElement, otherElement)
.replaceWithMapping
in class ParallelArrayWithFilter<T>
other
- the other arraycombiner
- the combinerpublic int indexOf(T target)
indexOf
in class AbstractParallelAnyArray.OUPap<T>
target
- the element to search forpublic int binarySearch(T target)
binarySearch
in class AbstractParallelAnyArray.OUPap<T>
target
- the element to search forpublic int binarySearch(T target, java.util.Comparator<? super T> comparator)
binarySearch
in class AbstractParallelAnyArray.OUPap<T>
target
- the element to search forcomparator
- the comparatorpublic ParallelArray.SummaryStatistics<T> summary(java.util.Comparator<? super T> comparator)
summary
in class ParallelArrayWithMapping<T,T>
comparator
- the comparator to use for
locating minimum and maximum elementspublic ParallelArray.SummaryStatistics<T> summary()
summary
in class ParallelArrayWithMapping<T,T>
public T min(java.util.Comparator<? super T> comparator)
min
in class ParallelArrayWithMapping<T,T>
comparator
- the comparatorpublic T min()
min
in class ParallelArrayWithMapping<T,T>
java.lang.ClassCastException
- if any element is not Comparablepublic T max(java.util.Comparator<? super T> comparator)
max
in class ParallelArrayWithMapping<T,T>
comparator
- the comparatorpublic T max()
max
in class ParallelArrayWithMapping<T,T>
java.lang.ClassCastException
- if any element is not Comparablepublic ParallelArray<T> cumulate(Ops.Reducer<T> reducer, T base)
1, 2, 3
, and the reducer operation adds numbers, then
after invocation of this method, the contents would be 1,
3, 6
(that is, 1, 1+2, 1+2+3
).cumulate
in class AbstractParallelAnyArray.OUPap<T>
reducer
- the reducerbase
- the result for an empty arraypublic T precumulate(Ops.Reducer<T> reducer, T base)
1,
2, 3
, and the reducer operation adds numbers, then after
invocation of this method, the contents would be 0, 1,
3
(that is, 0, 0+1, 0+1+2
, and the return value
would be 6 (that is, 1+2+3
).precumulate
in class AbstractParallelAnyArray.OUPap<T>
reducer
- the reducerbase
- the result for an empty arraypublic ParallelArray<T> sort(java.util.Comparator<? super T> comparator)
sort
in class AbstractParallelAnyArray.OUPap<T>
comparator
- the comparator to usepublic ParallelArray<T> sort()
sort
in class AbstractParallelAnyArray.OUPap<T>
java.lang.ClassCastException
- if any element is not Comparablepublic ParallelArray<T> allUniqueElements()
equals
method to test for duplication.allUniqueElements
in class ParallelArrayWithFilter<T>
public ParallelArray<T> allNonidenticalElements()
allNonidenticalElements
in class ParallelArrayWithFilter<T>
public ParallelArray<T> removeAll(Ops.Predicate<? super T> selector)
selector
- the selectorpublic <U,V> boolean hasAllEqualElements(ParallelArrayWithMapping<U,V> other)
hasAllEqualElements
in class ParallelArrayWithFilter<T>
other
- the other arraypublic <U,V> boolean hasAllIdenticalElements(ParallelArrayWithMapping<U,V> other)
hasAllIdenticalElements
in class ParallelArrayWithFilter<T>
other
- the other arraypublic ParallelArray<T> removeConsecutiveDuplicates()
public ParallelArray<T> removeNulls()
public ParallelArray<T> addAll(T[] other)
asList().addAll
but specialized for array
arguments and likely to be more efficient.other
- the elements to addpublic <V> ParallelArray<T> addAll(ParallelArrayWithMapping<V,T> other)
other
- the elements to addpublic ParallelArrayWithBounds<T> withBounds(int firstIndex, int upperBound)
withBounds
in class AbstractParallelAnyArray.OUPap<T>
firstIndex
- the lower bound (inclusive)upperBound
- the upper bound (exclusive)public ParallelArrayWithFilter<T> withFilter(Ops.Predicate<? super T> selector)
withFilter
in class AbstractParallelAnyArray.OUPap<T>
selector
- the selectorpublic <V,W> ParallelArrayWithFilter<T> withFilter(Ops.BinaryPredicate<? super T,? super V> selector, ParallelArrayWithMapping<W,V> other)
withFilter
in class ParallelArrayWithFilter<T>
selector
- the selectorpublic ParallelArrayWithFilter<T> withIndexedFilter(Ops.IntAndObjectPredicate<? super T> selector)
withIndexedFilter
in class AbstractParallelAnyArray.OUPap<T>
selector
- the selectorpublic <U> ParallelArrayWithMapping<T,U> withMapping(Ops.Op<? super T,? extends U> op)
withMapping
in class AbstractParallelAnyArray.OUPap<T>
op
- the oppublic ParallelArrayWithDoubleMapping<T> withMapping(Ops.ObjectToDouble<? super T> op)
withMapping
in class AbstractParallelAnyArray.OUPap<T>
op
- the oppublic ParallelArrayWithLongMapping<T> withMapping(Ops.ObjectToLong<? super T> op)
withMapping
in class AbstractParallelAnyArray.OUPap<T>
op
- the oppublic <U,V,W> ParallelArrayWithMapping<T,V> withMapping(Ops.BinaryOp<? super T,? super U,? extends V> combiner, ParallelArrayWithMapping<W,U> other)
withMapping
in class ParallelArrayWithMapping<T,T>
combiner
- the combinerother
- the other arrayjava.lang.IllegalArgumentException
- if other array is a
filtered view (all filters must precede all mappings)public <V> ParallelArrayWithMapping<T,V> withMapping(Ops.ObjectAndDoubleToObject<? super T,? extends V> combiner, ParallelDoubleArrayWithDoubleMapping other)
withMapping
in class ParallelArrayWithMapping<T,T>
combiner
- the combinerother
- the other arrayjava.lang.IllegalArgumentException
- if other array is a
filtered view (all filters must precede all mappings)public <V> ParallelArrayWithMapping<T,V> withMapping(Ops.ObjectAndLongToObject<? super T,? extends V> combiner, ParallelLongArrayWithLongMapping other)
withMapping
in class ParallelArrayWithMapping<T,T>
combiner
- the combinerother
- the other arrayjava.lang.IllegalArgumentException
- if other array is a
filtered view (all filters must precede all mappings)public <U,W> ParallelArrayWithDoubleMapping<T> withMapping(Ops.ObjectAndObjectToDouble<? super T,? super U> combiner, ParallelArrayWithMapping<W,U> other)
withMapping
in class ParallelArrayWithMapping<T,T>
combiner
- the combinerother
- the other arrayjava.lang.IllegalArgumentException
- if other array is a
filtered view (all filters must precede all mappings)public ParallelArrayWithDoubleMapping<T> withMapping(Ops.ObjectAndDoubleToDouble<? super T> combiner, ParallelDoubleArrayWithDoubleMapping other)
withMapping
in class ParallelArrayWithMapping<T,T>
combiner
- the combinerother
- the other arrayjava.lang.IllegalArgumentException
- if other array is a
filtered view (all filters must precede all mappings)public ParallelArrayWithDoubleMapping<T> withMapping(Ops.ObjectAndLongToDouble<? super T> combiner, ParallelLongArrayWithLongMapping other)
withMapping
in class ParallelArrayWithMapping<T,T>
combiner
- the combinerother
- the other arrayjava.lang.IllegalArgumentException
- if other array is a
filtered view (all filters must precede all mappings)public <U,W> ParallelArrayWithLongMapping<T> withMapping(Ops.ObjectAndObjectToLong<? super T,? super U> combiner, ParallelArrayWithMapping<W,U> other)
withMapping
in class ParallelArrayWithMapping<T,T>
combiner
- the combinerother
- the other arrayjava.lang.IllegalArgumentException
- if other array is a
filtered view (all filters must precede all mappings)public ParallelArrayWithLongMapping<T> withMapping(Ops.ObjectAndDoubleToLong<? super T> combiner, ParallelDoubleArrayWithDoubleMapping other)
withMapping
in class ParallelArrayWithMapping<T,T>
combiner
- the combinerother
- the other arrayjava.lang.IllegalArgumentException
- if other array is a
filtered view (all filters must precede all mappings)public ParallelArrayWithLongMapping<T> withMapping(Ops.ObjectAndLongToLong<? super T> combiner, ParallelLongArrayWithLongMapping other)
withMapping
in class ParallelArrayWithMapping<T,T>
combiner
- the combinerother
- the other arrayjava.lang.IllegalArgumentException
- if other array is a
filtered view (all filters must precede all mappings)public <U> ParallelArrayWithMapping<T,U> withIndexedMapping(Ops.IntAndObjectToObject<? super T,? extends U> mapper)
withIndexedMapping
in class AbstractParallelAnyArray.OUPap<T>
mapper
- the mapperpublic ParallelArrayWithDoubleMapping<T> withIndexedMapping(Ops.IntAndObjectToDouble<? super T> mapper)
withIndexedMapping
in class AbstractParallelAnyArray.OUPap<T>
mapper
- the mapperpublic ParallelArrayWithLongMapping<T> withIndexedMapping(Ops.IntAndObjectToLong<? super T> mapper)
withIndexedMapping
in class AbstractParallelAnyArray.OUPap<T>
mapper
- the mapperpublic java.util.Iterator<T> iterator()
ListIterator
supporting add, remove, and set
operations is available via asList()
.iterator
in interface java.lang.Iterable<T>
public java.util.List<T> asList()
ArrayList
, and may be used to modify, replace or extend the
bounds of the array underlying this ParallelArray. The methods
supported by this list view are not in general
implemented as parallel operations. This list is also not
itself thread-safe. In particular, performing list updates
while other parallel operations are in progress has undefined
(and surely undesired) effects.public int size()
setLimit(int)
), or the length of the array otherwise.size
in class AbstractParallelAnyArray
public T get(int i)
i
- the indexpublic void set(int i, T x)
i
- the indexx
- the valuepublic T[] getArray()
public java.lang.String toString()
asList().toString()
.toString
in class java.lang.Object
public final void setLimit(int newLimit)
newLimit
- the new upper boundjava.lang.IllegalArgumentException
- if newLimit less than zerofinal void replaceElementsWith(T[] a)
final void resizeArray(int newCap)
final void insertElementAt(int index, T e)
final void appendElement(T e)
final void insertSlotsAt(int index, int len)
final void removeSlotAt(int index)
final void removeSlotsAt(int fromIndex, int toIndex)
final int seqIndexOf(java.lang.Object target)
final int seqLastIndexOf(java.lang.Object target)