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