|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjsr166y.forkjoin.ParallelDoubleArray
public class ParallelDoubleArray
An array of doubles supporting parallel operations. This class
provides methods supporting the same operations as ParallelArray
, but specialized for scalar doubles. It additionally
provides a few methods specific to numerical values.
Nested Class Summary | |
---|---|
static interface |
ParallelDoubleArray.SummaryStatistics
Summary statistics for a possibly bounded, filtered, and/or mapped ParallelDoubleArray. |
static class |
ParallelDoubleArray.WithBounds
A restriction of parallel array operations to apply only within a given range of indices. |
static class |
ParallelDoubleArray.WithDoubleMapping
A modifier for parallel array operations to apply to mappings of elements to doubles, not to the elements themselves |
static class |
ParallelDoubleArray.WithFilter
A restriction of parallel array operations to apply only to elements for which a selector returns true |
static class |
ParallelDoubleArray.WithLongMapping
A modifier for parallel array operations to apply to mappings of elements to longs, not to the elements themselves |
static class |
ParallelDoubleArray.WithMapping<U>
A modifier for parallel array operations to apply to mappings of elements, not to the elements themselves |
Constructor Summary | |
---|---|
protected |
ParallelDoubleArray(ForkJoinExecutor executor,
double[] array,
int limit)
Constructor for use by subclasses to create a new ParallelDoubleArray using the given executor, and initially using the supplied array, with effective size bound by the given limit. |
Method Summary | ||
---|---|---|
void |
addAll(double[] other)
Equivalent to AsList.addAll but specialized for array arguments and likely to be more efficient. |
|
void |
addAll(ParallelDoubleArray.WithBounds other)
Equivalent to AsList.addAll but specialized for ParallelDoubleArray arguments and likely to be more efficient. |
|
void |
addAll(ParallelDoubleArray other)
Equivalent to AsList.addAll but specialized for ParallelDoubleArray arguments and likely to be more efficient. |
|
ParallelDoubleArray |
all()
Returns a new ParallelDoubleArray holding all elements |
|
ParallelDoubleArray |
allUniqueElements()
Returns a new ParallelDoubleArray containing only the unique elements of this array (that is, without any duplicates). |
|
void |
apply(Ops.DoubleProcedure procedure)
Applies the given procedure to elements |
|
java.util.List<java.lang.Double> |
asList()
Returns a view of this ParallelDoubleArray as a List. |
|
int |
binarySearch(double target)
Assuming this array is sorted, returns the index of an element equal to given target, or -1 if not present. |
|
int |
binarySearch(double target,
Ops.DoubleComparator 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. |
|
ParallelDoubleArray |
combine(double[] other,
Ops.DoubleReducer combiner)
Returns a ParallelDoubleArray containing results of applying combine(thisElement, otherElement) for each element. |
|
|
combine(ParallelDoubleArray.WithBounds other,
Ops.DoubleReducer combiner)
Returns a ParallelDoubleArray containing results of applying combine(thisElement, otherElement) for each element. |
|
|
combine(ParallelDoubleArray other,
Ops.DoubleReducer combiner)
Returns a ParallelDoubleArray containing results of applying combine(thisElement, otherElement) for each element. |
|
static ParallelDoubleArray |
create(int size,
ForkJoinExecutor executor)
Creates a new ParallelDoubleArray using the given executor and an array of the given size |
|
static ParallelDoubleArray |
createEmpty(int size,
ForkJoinExecutor executor)
Creates a new ParallelDoubleArray using the given executor and an array of the given size, but with an initial effective size of zero, enabling incremental insertion via asList() operations. |
|
static ParallelDoubleArray |
createFromCopy(double[] source,
ForkJoinExecutor executor)
Creates a new ParallelDoubleArray using the given executor and initially holding copies of the given source elements. |
|
static ParallelDoubleArray |
createFromCopy(int size,
double[] source,
ForkJoinExecutor executor)
Creates a new ParallelDoubleArray using an array of the given size, initially holding copies of the given source truncated or padded with zeros to obtain the specified length. |
|
static ParallelDoubleArray |
createUsingHandoff(double[] handoff,
ForkJoinExecutor executor)
Creates a new ParallelDoubleArray initially using the given array and executor. |
|
void |
cumulate(Ops.DoubleReducer reducer,
double base)
Replaces each element with the running cumulation of applying the given reducer. |
|
void |
cumulateSum()
Replaces each element with the running sum |
|
static ForkJoinExecutor |
defaultExecutor()
Returns a common default executor for use in ParallelArrays. |
|
double |
get(int i)
Returns the element of the array at the given index |
|
double[] |
getArray()
Returns the underlying array used for computations |
|
ForkJoinExecutor |
getExecutor()
Returns the executor used for computations |
|
int |
indexOf(double target)
Returns the index of some element equal to given target, or -1 if not present |
|
java.util.Iterator<java.lang.Double> |
iterator()
Returns an iterator stepping through each element of the array up to the current limit. |
|
double |
max()
Returns the maximum element, or -Double.MAX_VALUE if empty |
|
double |
max(Ops.DoubleComparator comparator)
Returns the maximum element, or -Double.MAX_VALUE if empty |
|
double |
min()
Returns the minimum element, or Double.MAX_VALUE if empty, |
|
double |
min(Ops.DoubleComparator comparator)
Returns the minimum element, or Double.MAX_VALUE if empty |
|
double |
precumulate(Ops.DoubleReducer reducer,
double base)
Replaces each element with the cumulation of applying the given reducer to all previous values, and returns the total reduction. |
|
double |
precumulateSum()
Replaces each element with its prefix sum |
|
double |
reduce(Ops.DoubleReducer reducer,
double base)
Returns reduction of elements |
|
void |
removeConsecutiveDuplicates()
Removes consecutive elements that are equal, shifting others leftward, and possibly decreasing size. |
|
void |
replaceWithCombination(double[] other,
Ops.DoubleReducer combiner)
Replaces elements with results of applying combine(thisElement, otherElement) |
|
void |
replaceWithCombination(ParallelDoubleArray.WithBounds other,
Ops.DoubleReducer combiner)
Replaces elements with results of applying combine(thisElement, otherElement) |
|
void |
replaceWithCombination(ParallelDoubleArray other,
Ops.DoubleReducer combiner)
Replaces elements with results of applying combine(thisElement, otherElement) |
|
void |
replaceWithGeneratedValue(Ops.DoubleGenerator generator)
Replaces elements with the results of applying the given generator. |
|
void |
replaceWithMappedIndex(Ops.MapperFromIntToDouble mapper)
Replaces elements with the results of applying the given mapper to their indices. |
|
void |
replaceWithTransform(Ops.DoubleMapper mapper)
Replaces elements with the results of applying the given mapper to their current values. |
|
void |
replaceWithValue(double value)
Replaces elements with the given value. |
|
void |
set(int i,
double 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. |
|
void |
sort()
Sorts the array, assuming all elements are Comparable. |
|
void |
sort(Ops.DoubleComparator comparator)
Sorts the array. |
|
double |
sum()
Returns the sum of elements |
|
ParallelDoubleArray.SummaryStatistics |
summary()
Returns summary statistics, using natural comparator |
|
ParallelDoubleArray.SummaryStatistics |
summary(Ops.DoubleComparator comparator)
Returns summary statistics, using the given comparator to locate minimum and maximum elements. |
|
java.lang.String |
toString()
Equivalent to asList().toString() |
|
ParallelDoubleArray.WithBounds |
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). |
|
ParallelDoubleArray.WithFilter |
withFilter(Ops.DoublePredicate 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 |
|
ParallelDoubleArray.WithDoubleMapping |
withMapping(Ops.DoubleMapper mapper)
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given mapper. |
|
|
withMapping(Ops.MapperFromDouble<? extends U> mapper)
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given mapper. |
|
ParallelDoubleArray.WithLongMapping |
withMapping(Ops.MapperFromDoubleToLong mapper)
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given mapper. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected ParallelDoubleArray(ForkJoinExecutor executor, double[] array, int limit)
create(int, jsr166y.forkjoin.ForkJoinExecutor)
,
createEmpty(int, jsr166y.forkjoin.ForkJoinExecutor)
, createUsingHandoff(double[], jsr166y.forkjoin.ForkJoinExecutor)
or createFromCopy(double[], jsr166y.forkjoin.ForkJoinExecutor)
.
executor
- the executorarray
- the arraylimit
- the upper bound limitMethod Detail |
---|
public static ForkJoinExecutor defaultExecutor()
public static ParallelDoubleArray create(int size, ForkJoinExecutor executor)
size
- the array sizeexecutor
- the executorpublic static ParallelDoubleArray createUsingHandoff(double[] handoff, ForkJoinExecutor executor)
handoff
- the arrayexecutor
- the executorpublic static ParallelDoubleArray createFromCopy(double[] source, ForkJoinExecutor executor)
source
- the source of initial elementsexecutor
- the executorpublic static ParallelDoubleArray createFromCopy(int size, double[] source, ForkJoinExecutor executor)
source
- the source of initial elementssize
- the array sizeexecutor
- the executorpublic static ParallelDoubleArray createEmpty(int size, ForkJoinExecutor executor)
asList()
operations.
size
- the array sizeexecutor
- the executorpublic ForkJoinExecutor getExecutor()
public void apply(Ops.DoubleProcedure procedure)
procedure
- the procedurepublic double reduce(Ops.DoubleReducer reducer, double base)
reducer
- the reducerbase
- the result for an empty array
public ParallelDoubleArray all()
public ParallelDoubleArray combine(double[] other, Ops.DoubleReducer combiner)
other
- the other arraycombiner
- the combiner
java.lang.ArrayIndexOutOfBoundsException
- if other array is
shorter than this array.public <U,V> ParallelDoubleArray combine(ParallelDoubleArray other, Ops.DoubleReducer combiner)
other
- the other arraycombiner
- the combiner
java.lang.ArrayIndexOutOfBoundsException
- if other array is not
the same length as this array.public <U,V> ParallelDoubleArray combine(ParallelDoubleArray.WithBounds other, Ops.DoubleReducer combiner)
other
- the other array segmentcombiner
- the combiner
java.lang.ArrayIndexOutOfBoundsException
- if other segment is
shorter than this array.public void replaceWithTransform(Ops.DoubleMapper mapper)
mapper
- the mapperpublic void replaceWithMappedIndex(Ops.MapperFromIntToDouble mapper)
mapper
- the mapperpublic void replaceWithGeneratedValue(Ops.DoubleGenerator generator)
generator
- the generatorpublic void replaceWithValue(double value)
value
- the valuepublic void replaceWithCombination(ParallelDoubleArray other, Ops.DoubleReducer combiner)
other
- the other arraycombiner
- the combiner
java.lang.ArrayIndexOutOfBoundsException
- if other array has
fewer elements than this array.public void replaceWithCombination(double[] other, Ops.DoubleReducer combiner)
other
- the other arraycombiner
- the combiner
java.lang.ArrayIndexOutOfBoundsException
- if other array has
fewer elements than this array.public void replaceWithCombination(ParallelDoubleArray.WithBounds other, Ops.DoubleReducer combiner)
other
- the other array segmentcombiner
- the combiner
java.lang.ArrayIndexOutOfBoundsException
- if other segment has
fewer elements.than this array,public int indexOf(double target)
target
- the element to search for
public int binarySearch(double target)
target
- the element to search for
public int binarySearch(double target, Ops.DoubleComparator comparator)
target
- the element to search forcomparator
- the comparator
public ParallelDoubleArray.SummaryStatistics summary(Ops.DoubleComparator comparator)
comparator
- the comparator to use for
locating minimum and maximum elements
public ParallelDoubleArray.SummaryStatistics summary()
public double min(Ops.DoubleComparator comparator)
comparator
- the comparator
public double min()
public double max(Ops.DoubleComparator comparator)
comparator
- the comparator
public double max()
public void cumulate(Ops.DoubleReducer reducer, double base)
reducer
- the reducerbase
- the result for an empty arraypublic double precumulate(Ops.DoubleReducer reducer, double base)
reducer
- the reducerbase
- the result for an empty array
public void sort(Ops.DoubleComparator comparator)
comparator
- the comparator to usepublic void sort()
java.lang.ClassCastException
- if any element is not Comparable.public void removeConsecutiveDuplicates()
public ParallelDoubleArray allUniqueElements()
public double sum()
public void cumulateSum()
public double precumulateSum()
public ParallelDoubleArray.WithBounds withBounds(int firstIndex, int upperBound)
firstIndex
- the lower bound (inclusive)upperBound
- the upper bound (exclusive)
public ParallelDoubleArray.WithFilter withFilter(Ops.DoublePredicate selector)
selector
- the selector
public <U> ParallelDoubleArray.WithMapping<U> withMapping(Ops.MapperFromDouble<? extends U> mapper)
mapper
- the mapper
public ParallelDoubleArray.WithDoubleMapping withMapping(Ops.DoubleMapper mapper)
mapper
- the mapper
public ParallelDoubleArray.WithLongMapping withMapping(Ops.MapperFromDoubleToLong mapper)
mapper
- the mapper
public java.util.Iterator<java.lang.Double> iterator()
asList()
.
public java.util.List<java.lang.Double> asList()
ArrayList
, and may be used to modify, replace or extend
the bounds of the array underlying this ParallelDoubleArray.
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.
public double[] getArray()
public double get(int i)
i
- the index
public void set(int i, double x)
i
- the indexx
- the valuepublic java.lang.String toString()
toString
in class java.lang.Object
public void addAll(double[] other)
other
- the elements to addpublic void addAll(ParallelDoubleArray other)
other
- the elements to addpublic void addAll(ParallelDoubleArray.WithBounds other)
other
- the elements to addpublic final void setLimit(int newLimit)
newLimit
- the new upper bound
java.lang.IllegalArgumentException
- if newLimit less than zero.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |