|
org.codehaus.gpars | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object AbstractParallelAnyArray.LUPap groovyx.gpars.extra166y.ParallelLongArray
public class ParallelLongArray extends LUPap
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.
Sample usages. Here is a complete (although naive) prime filter program:
import java.math.BigInteger; import jsr166y.*; import static extra166y.Ops.*; import static extra166y.ParallelLongArray.*; public class Sieve { public static void main(String[] args) { int n = Integer.parseInt(args[0]); // create array of divisors ParallelLongArray a = create(n-1, defaultExecutor()); a.replaceWithMappedIndex(add2); int i = 0; long p = 2; while (p * p < n) { // repeatedly filter a = a.withFilter(notDivisibleBy(p)).all(); p = a.get(++i); } System.out.printf("sieve(%d) = %s%n", n, a); // check result if (!a.withFilter(notProbablePrime).isEmpty()) throw new Error(); } static IntToLong add2 = new IntToLong() { public long op(int i) { return i + 2; } }; static LongPredicate notDivisibleBy(final long p) { return new LongPredicate() { public boolean op(long n) { return n <= p || (n % p) != 0; } }; } static LongPredicate notProbablePrime = new LongPredicate() { private static final int CERTAINTY = 8; public boolean op(long n) { return !BigInteger.valueOf(n).isProbablePrime(CERTAINTY); } }; }
Nested Class Summary | |
---|---|
class |
ParallelLongArray.AsList
|
class |
ParallelLongArray.ListIter
|
static class |
ParallelLongArray.ParallelLongArrayIterator
|
static interface |
ParallelLongArray.SummaryStatistics
Summary statistics for a possibly bounded, filtered, and/or mapped ParallelLongArray. |
Field Summary | |
---|---|
ParallelLongArray.AsList |
listView
|
Constructor Summary | |
protected ParallelLongArray(ForkJoinPool 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. |
|
ParallelLongArray(ForkJoinPool executor, long[] array)
Trusted internal version of protected constructor. |
Method Summary | |
---|---|
ParallelLongArray
|
addAll(long[] other)
Equivalent to asList().addAll but specialized for array arguments and likely to be more efficient. |
ParallelLongArray
|
addAll(ParallelLongArrayWithLongMapping other)
Appends all (possibly bounded, filtered, or mapped) elements of the given ParallelDoubleArray, resizing and/or reallocating this array if necessary. |
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
|
appendElement(long e)
|
void
|
apply(LongProcedure procedure)
Applies the given procedure to elements |
java.util.List
|
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, 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. |
static ParallelLongArray
|
create(int size, ForkJoinPool executor)
Creates a new ParallelLongArray using the given executor and an array of the given size |
static ParallelLongArray
|
createEmpty(int size, ForkJoinPool 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 ParallelLongArray#asList#asList operations. |
static ParallelLongArray
|
createFromCopy(long[] source, ForkJoinPool executor)
Creates a new ParallelLongArray using the given executor and initially holding copies of the given source elements. |
static ParallelLongArray
|
createFromCopy(int size, long[] source, ForkJoinPool 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
|
createUsingHandoff(long[] handoff, ForkJoinPool executor)
Creates a new ParallelLongArray initially using the given array and executor. |
ParallelLongArray
|
cumulate(LongReducer reducer, long base)
Replaces each element with the running cumulation of applying the given reducer. |
ParallelLongArray
|
cumulateSum()
Replaces each element with the running sum |
static ForkJoinPool
|
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 |
ForkJoinPool
|
getExecutor()
Returns the executor used for computations |
boolean
|
hasAllEqualElements(ParallelLongArrayWithLongMapping other)
Returns true if all elements at the same relative positions of this and other array are equal. |
int
|
indexOf(long target)
Returns the index of some element equal to given target, or -1 if not present |
void
|
insertElementAt(int index, long e)
|
void
|
insertSlotsAt(int index, int len)
Makes len slots available at index. |
java.util.Iterator
|
iterator()
Returns an iterator stepping through each element of the array up to the current limit. |
long
|
max(LongComparator comparator)
Returns the maximum element, or Long.MIN_VALUE if empty |
long
|
max()
Returns the maximum element, or Long.MIN_VALUE if empty |
long
|
min(LongComparator comparator)
Returns the minimum element, or Long.MAX_VALUE if empty |
long
|
min()
Returns the minimum element, or Long.MAX_VALUE if empty, |
long
|
precumulate(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(LongReducer reducer, long base)
Returns reduction of elements |
ParallelLongArray
|
removeAll(LongPredicate selector)
Removes from the array all elements for which the given selector holds. |
ParallelLongArray
|
removeConsecutiveDuplicates()
Removes consecutive elements that are equal, shifting others leftward, and possibly decreasing size. |
void
|
removeSlotAt(int index)
|
void
|
removeSlotsAt(int fromIndex, int toIndex)
|
void
|
replaceElementsParallelLongArrayWith(long[] a)
|
ParallelLongArray
|
replaceWithGeneratedValue(LongGenerator generator)
Replaces elements with the results of applying the given generator. |
ParallelLongArray
|
replaceWithMappedIndex(IntToLong op)
Replaces elements with the results of applying the given op to their indices. |
ParallelLongArray
|
replaceWithMappedIndex(IntAndLongToLong op)
Replaces elements with the results of applying the given mapping to each index and current element value |
ParallelLongArray
|
replaceWithMapping(LongOp op)
Replaces elements with the results of applying the given op to their current values. |
ParallelLongArray
|
replaceWithMapping(BinaryLongOp combiner, ParallelLongArrayWithLongMapping other)
Replaces elements with results of applying op(thisElement, otherElement) |
ParallelLongArray
|
replaceWithMapping(BinaryLongOp combiner, long[] other)
Replaces elements with results of applying op(thisElement, otherElement) |
ParallelLongArray
|
replaceWithValue(long value)
Replaces elements with the given value. |
void
|
resizeArray(int newCap)
|
int
|
seqIndexOf(long target)
|
int
|
seqLastIndexOf(long target)
|
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. |
ParallelLongArray
|
sort(LongComparator comparator)
Sorts the array. |
ParallelLongArray
|
sort()
Sorts the array, assuming all elements are Comparable. |
long
|
sum()
Returns the sum of elements |
SummaryStatistics
|
summary(LongComparator comparator)
Returns summary statistics, using the given comparator to locate minimum and maximum elements. |
SummaryStatistics
|
summary()
Returns summary statistics, using natural comparator |
java.lang.String
|
toString()
Equivalent to asList().toString() |
ParallelLongArrayWithBounds
|
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). |
ParallelLongArrayWithFilter
|
withFilter(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 |
ParallelLongArrayWithFilter
|
withFilter(BinaryLongPredicate selector, ParallelLongArrayWithLongMapping other)
Returns an operation prefix that causes a method to operate only on elements for which the given binary selector returns true |
ParallelLongArrayWithFilter
|
withIndexedFilter(IntAndLongPredicate selector)
Returns an operation prefix that causes a method to operate only on elements for which the given indexed selector returns true |
ParallelLongArrayWithMapping
|
withIndexedMapping(IntAndLongToObject 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. |
ParallelLongArrayWithDoubleMapping
|
withIndexedMapping(IntAndLongToDouble 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. |
ParallelLongArrayWithLongMapping
|
withIndexedMapping(IntAndLongToLong 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. |
ParallelLongArrayWithMapping
|
withMapping(LongToObject op)
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given op. |
ParallelLongArrayWithLongMapping
|
withMapping(LongOp op)
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given op. |
ParallelLongArrayWithDoubleMapping
|
withMapping(LongToDouble op)
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given op. |
ParallelLongArrayWithMapping
|
withMapping(LongAndObjectToObject combiner, ParallelArrayWithMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array. |
ParallelLongArrayWithMapping
|
withMapping(LongAndDoubleToObject combiner, ParallelDoubleArrayWithDoubleMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array. |
ParallelLongArrayWithMapping
|
withMapping(LongAndLongToObject combiner, ParallelLongArrayWithLongMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array. |
ParallelLongArrayWithDoubleMapping
|
withMapping(LongAndObjectToDouble combiner, ParallelArrayWithMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array. |
ParallelLongArrayWithDoubleMapping
|
withMapping(LongAndDoubleToDouble combiner, ParallelDoubleArrayWithDoubleMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array. |
ParallelLongArrayWithDoubleMapping
|
withMapping(LongAndLongToDouble combiner, ParallelLongArrayWithLongMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array. |
ParallelLongArrayWithLongMapping
|
withMapping(LongAndObjectToLong combiner, ParallelArrayWithMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array. |
ParallelLongArrayWithLongMapping
|
withMapping(LongAndDoubleToLong combiner, ParallelDoubleArrayWithDoubleMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array. |
ParallelLongArrayWithLongMapping
|
withMapping(BinaryLongOp combiner, ParallelLongArrayWithLongMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array. |
Field Detail |
---|
ParallelLongArray.AsList listView
Constructor Detail |
---|
protected ParallelLongArray(ForkJoinPool executor, long[] array, int limit)
executor
- the executorarray
- the arraylimit
- the upper bound limit
ParallelLongArray(ForkJoinPool executor, long[] array)
Method Detail |
---|
public ParallelLongArray addAll(long[] other)
other
- the elements to add
public ParallelLongArray addAll(ParallelLongArrayWithLongMapping other)
other
- the elements to add
public ParallelLongArray all()
public ParallelLongArray allUniqueElements()
final void appendElement(long e)
public void apply(LongProcedure procedure)
procedure
- the procedure
public java.util.List asList()
public int binarySearch(long target)
target
- the element to search for
public int binarySearch(long target, LongComparator comparator)
target
- the element to search forcomparator
- the comparator
public static ParallelLongArray create(int size, ForkJoinPool executor)
size
- the array sizeexecutor
- the executor
public static ParallelLongArray createEmpty(int size, ForkJoinPool executor)
size
- the array sizeexecutor
- the executor
public static ParallelLongArray createFromCopy(long[] source, ForkJoinPool executor)
source
- the source of initial elementsexecutor
- the executor
public static ParallelLongArray createFromCopy(int size, long[] source, ForkJoinPool executor)
source
- the source of initial elementssize
- the array sizeexecutor
- the executor
public static ParallelLongArray createUsingHandoff(long[] handoff, ForkJoinPool executor)
handoff
- the arrayexecutor
- the executor
public ParallelLongArray cumulate(LongReducer reducer, long base)
reducer
- the reducerbase
- the result for an empty array
public ParallelLongArray cumulateSum()
public static ForkJoinPool defaultExecutor()
public long get(int i)
i
- the index
public long[] getArray()
public ForkJoinPool getExecutor()
public boolean hasAllEqualElements(ParallelLongArrayWithLongMapping other)
other
- the other array
public int indexOf(long target)
target
- the element to search for
final void insertElementAt(int index, long e)
final void insertSlotsAt(int index, int len)
public java.util.Iterator iterator()
public long max(LongComparator comparator)
comparator
- the comparator
public long max()
public long min(LongComparator comparator)
comparator
- the comparator
public long min()
public long precumulate(LongReducer reducer, long base)
reducer
- the reducerbase
- the result for an empty array
public long precumulateSum()
public long reduce(LongReducer reducer, long base)
reducer
- the reducerbase
- the result for an empty array
public ParallelLongArray removeAll(LongPredicate selector)
selector
- the selector
public ParallelLongArray removeConsecutiveDuplicates()
final void removeSlotAt(int index)
final void removeSlotsAt(int fromIndex, int toIndex)
final void replaceElementsParallelLongArrayWith(long[] a)
public ParallelLongArray replaceWithGeneratedValue(LongGenerator generator)
generator
- the generator
public ParallelLongArray replaceWithMappedIndex(IntToLong op)
op
- the op
public ParallelLongArray replaceWithMappedIndex(IntAndLongToLong op)
op
- the op
public ParallelLongArray replaceWithMapping(LongOp op)
op
- the op
public ParallelLongArray replaceWithMapping(BinaryLongOp combiner, ParallelLongArrayWithLongMapping other)
other
- the other arraycombiner
- the combiner
public ParallelLongArray replaceWithMapping(BinaryLongOp combiner, long[] other)
other
- the other arraycombiner
- the combiner
public ParallelLongArray replaceWithValue(long value)
value
- the value
final void resizeArray(int newCap)
final int seqIndexOf(long target)
final int seqLastIndexOf(long target)
public void set(int i, long x)
i
- the indexx
- the value
public final void setLimit(int newLimit)
newLimit
- the new upper bound
public int size()
public ParallelLongArray sort(LongComparator comparator)
comparator
- the comparator to use
public ParallelLongArray sort()
public long sum()
public SummaryStatistics summary(LongComparator comparator)
comparator
- the comparator to use for
locating minimum and maximum elements
public SummaryStatistics summary()
public java.lang.String toString()
public ParallelLongArrayWithBounds withBounds(int firstIndex, int upperBound)
firstIndex
- the lower bound (inclusive)upperBound
- the upper bound (exclusive)
public ParallelLongArrayWithFilter withFilter(LongPredicate selector)
selector
- the selector
public ParallelLongArrayWithFilter withFilter(BinaryLongPredicate selector, ParallelLongArrayWithLongMapping other)
selector
- the selector
public ParallelLongArrayWithFilter withIndexedFilter(IntAndLongPredicate selector)
selector
- the selector
public ParallelLongArrayWithMapping withIndexedMapping(IntAndLongToObject mapper)
mapper
- the mapper
public ParallelLongArrayWithDoubleMapping withIndexedMapping(IntAndLongToDouble mapper)
mapper
- the mapper
public ParallelLongArrayWithLongMapping withIndexedMapping(IntAndLongToLong mapper)
mapper
- the mapper
public ParallelLongArrayWithMapping withMapping(LongToObject op)
op
- the op
public ParallelLongArrayWithLongMapping withMapping(LongOp op)
op
- the op
public ParallelLongArrayWithDoubleMapping withMapping(LongToDouble op)
op
- the op
public ParallelLongArrayWithMapping withMapping(LongAndObjectToObject combiner, ParallelArrayWithMapping other)
combiner
- the combinerother
- the other array
public ParallelLongArrayWithMapping withMapping(LongAndDoubleToObject combiner, ParallelDoubleArrayWithDoubleMapping other)
combiner
- the combinerother
- the other array
public ParallelLongArrayWithMapping withMapping(LongAndLongToObject combiner, ParallelLongArrayWithLongMapping other)
combiner
- the combinerother
- the other array
public ParallelLongArrayWithDoubleMapping withMapping(LongAndObjectToDouble combiner, ParallelArrayWithMapping other)
combiner
- the combinerother
- the other array
public ParallelLongArrayWithDoubleMapping withMapping(LongAndDoubleToDouble combiner, ParallelDoubleArrayWithDoubleMapping other)
combiner
- the combinerother
- the other array
public ParallelLongArrayWithDoubleMapping withMapping(LongAndLongToDouble combiner, ParallelLongArrayWithLongMapping other)
combiner
- the combinerother
- the other array
public ParallelLongArrayWithLongMapping withMapping(LongAndObjectToLong combiner, ParallelArrayWithMapping other)
combiner
- the combinerother
- the other array
public ParallelLongArrayWithLongMapping withMapping(LongAndDoubleToLong combiner, ParallelDoubleArrayWithDoubleMapping other)
combiner
- the combinerother
- the other array
public ParallelLongArrayWithLongMapping withMapping(BinaryLongOp combiner, ParallelLongArrayWithLongMapping other)
combiner
- the combinerother
- the other array
Copyright © 2008–2012 Václav Pech. All Rights Reserved.