groovyx.gpars.extra166y
Class ParallelLongArray

java.lang.Object
  extended by groovyx.gpars.extra166y.AbstractParallelAnyArray
      extended by groovyx.gpars.extra166y.AbstractParallelAnyArray.LPap
          extended by groovyx.gpars.extra166y.ParallelLongArrayWithLongMapping
              extended by groovyx.gpars.extra166y.ParallelLongArrayWithFilter
                  extended by groovyx.gpars.extra166y.ParallelLongArrayWithBounds
                      extended by groovyx.gpars.extra166y.AbstractParallelAnyArray.LUPap
                          extended by groovyx.gpars.extra166y.ParallelLongArray

public class ParallelLongArray
extends AbstractParallelAnyArray.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
(package private)  class ParallelLongArray.AsList
           
(package private)  class ParallelLongArray.ListIter
           
(package private) static class ParallelLongArray.ParallelLongArrayIterator
           
static interface ParallelLongArray.SummaryStatistics
          Summary statistics for a possibly bounded, filtered, and/or mapped ParallelLongArray.
 
Nested classes/interfaces inherited from class groovyx.gpars.extra166y.AbstractParallelAnyArray
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>
 
Field Summary
(package private)  ParallelLongArray.AsList listView
           
 
Fields inherited from class groovyx.gpars.extra166y.AbstractParallelAnyArray.LPap
array
 
Fields inherited from class groovyx.gpars.extra166y.AbstractParallelAnyArray
ex, fence, origin, threshold
 
Constructor Summary
(package private) ParallelLongArray(jsr166y.ForkJoinPool executor, long[] array)
          Trusted internal version of protected constructor.
protected ParallelLongArray(jsr166y.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.
 
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).
(package private)  void appendElement(long e)
           
 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.
static ParallelLongArray create(int size, jsr166y.ForkJoinPool executor)
          Creates a new ParallelLongArray using the given executor and an array of the given size
static ParallelLongArray createEmpty(int size, jsr166y.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 asList() operations.
static ParallelLongArray createFromCopy(int size, long[] source, jsr166y.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 createFromCopy(long[] source, jsr166y.ForkJoinPool executor)
          Creates a new ParallelLongArray using the given executor and initially holding copies of the given source elements.
static ParallelLongArray createUsingHandoff(long[] handoff, jsr166y.ForkJoinPool executor)
          Creates a new ParallelLongArray initially using the given array and executor.
 ParallelLongArray cumulate(Ops.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 jsr166y.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
 jsr166y.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
(package private)  void insertElementAt(int index, long e)
           
(package private)  void insertSlotsAt(int index, int len)
          Makes len slots available at index.
 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
 ParallelLongArray removeAll(Ops.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.
(package private)  void removeSlotAt(int index)
           
(package private)  void removeSlotsAt(int fromIndex, int toIndex)
           
(package private)  void replaceElementsParallelLongArrayWith(long[] a)
           
 ParallelLongArray replaceWithGeneratedValue(Ops.LongGenerator generator)
          Replaces elements with the results of applying the given generator.
 ParallelLongArray replaceWithMappedIndex(Ops.IntAndLongToLong op)
          Replaces elements with the results of applying the given mapping to each index and current element value
 ParallelLongArray replaceWithMappedIndex(Ops.IntToLong op)
          Replaces elements with the results of applying the given op to their indices.
 ParallelLongArray replaceWithMapping(Ops.BinaryLongOp combiner, long[] other)
          Replaces elements with results of applying op(thisElement, otherElement)
 ParallelLongArray replaceWithMapping(Ops.BinaryLongOp combiner, ParallelLongArrayWithLongMapping other)
          Replaces elements with results of applying op(thisElement, otherElement)
 ParallelLongArray replaceWithMapping(Ops.LongOp op)
          Replaces elements with the results of applying the given op to their current values.
 ParallelLongArray replaceWithValue(long value)
          Replaces elements with the given value.
(package private)  void resizeArray(int newCap)
           
(package private)  int seqIndexOf(long target)
           
(package private)  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()
          Sorts the array, assuming all elements are Comparable.
 ParallelLongArray 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()
 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(Ops.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 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
 ParallelLongArrayWithFilter withIndexedFilter(Ops.IntAndLongPredicate selector)
          Returns an operation prefix that causes a method to operate only on elements for which the given indexed selector returns true
 ParallelLongArrayWithDoubleMapping withIndexedMapping(Ops.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(Ops.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.
<U> ParallelLongArrayWithMapping<U>
withIndexedMapping(Ops.IntAndLongToObject<? 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.
 ParallelLongArrayWithLongMapping withMapping(Ops.BinaryLongOp 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(Ops.LongAndDoubleToDouble 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(Ops.LongAndDoubleToLong combiner, ParallelDoubleArrayWithDoubleMapping other)
          Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.
<V> ParallelLongArrayWithMapping<V>
withMapping(Ops.LongAndDoubleToObject<? 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.
 ParallelLongArrayWithDoubleMapping withMapping(Ops.LongAndLongToDouble combiner, ParallelLongArrayWithLongMapping other)
          Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.
<V> ParallelLongArrayWithMapping<V>
withMapping(Ops.LongAndLongToObject<? 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.
<V,W> ParallelLongArrayWithDoubleMapping
withMapping(Ops.LongAndObjectToDouble<? super V> combiner, ParallelArrayWithMapping<W,V> other)
          Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.
<V,W> ParallelLongArrayWithLongMapping
withMapping(Ops.LongAndObjectToLong<? super V> combiner, ParallelArrayWithMapping<W,V> other)
          Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.
<V,W,X> ParallelLongArrayWithMapping<W>
withMapping(Ops.LongAndObjectToObject<? super V,? extends W> combiner, ParallelArrayWithMapping<X,V> other)
          Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.
 ParallelLongArrayWithLongMapping withMapping(Ops.LongOp op)
          Returns an operation prefix that causes a method to operate on mapped elements of the array using the given op.
 ParallelLongArrayWithDoubleMapping withMapping(Ops.LongToDouble op)
          Returns an operation prefix that causes a method to operate on mapped elements of the array using the given op.
<U> ParallelLongArrayWithMapping<U>
withMapping(Ops.LongToObject<? extends U> op)
          Returns an operation prefix that causes a method to operate on mapped elements of the array using the given op.
 
Methods inherited from class groovyx.gpars.extra166y.AbstractParallelAnyArray.LUPap
leafApply, leafBinaryIndexMap, leafCombineInPlace, leafCombineInPlace, leafFill, leafGenerate, leafIndexMap, leafReduce, leafTransform
 
Methods inherited from class groovyx.gpars.extra166y.ParallelLongArrayWithFilter
leafTransfer, leafTransferByIndex, lget
 
Methods inherited from class groovyx.gpars.extra166y.ParallelLongArrayWithLongMapping
sequentially
 
Methods inherited from class groovyx.gpars.extra166y.AbstractParallelAnyArray.LPap
dget, leafMoveByIndex, leafMoveSelected, lgetArray, oget
 
Methods inherited from class groovyx.gpars.extra166y.AbstractParallelAnyArray
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, ogetArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

listView

ParallelLongArray.AsList listView
Constructor Detail

ParallelLongArray

protected ParallelLongArray(jsr166y.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. This constructor is designed to enable extensions via subclassing. To create a ParallelLongArray, use create(int, jsr166y.ForkJoinPool), createEmpty(int, jsr166y.ForkJoinPool), createUsingHandoff(long[], jsr166y.ForkJoinPool) or createFromCopy(long[], jsr166y.ForkJoinPool).

Parameters:
executor - the executor
array - the array
limit - the upper bound limit

ParallelLongArray

ParallelLongArray(jsr166y.ForkJoinPool executor,
                  long[] array)
Trusted internal version of protected constructor.

Method Detail

defaultExecutor

public static jsr166y.ForkJoinPool defaultExecutor()
Returns a common default executor for use in ParallelArrays. This executor arranges enough parallelism to use most, but not necessarily all, of the available processors on this system.

Returns:
the executor

create

public static ParallelLongArray create(int size,
                                       jsr166y.ForkJoinPool executor)
Creates a new ParallelLongArray using the given executor and an array of the given size

Parameters:
size - the array size
executor - the executor

createUsingHandoff

public static ParallelLongArray createUsingHandoff(long[] handoff,
                                                   jsr166y.ForkJoinPool executor)
Creates a new ParallelLongArray initially using the given array and executor. In general, the handed off array should not be used for other purposes once constructing this ParallelLongArray. The given array may be internally replaced by another array in the course of methods that add or remove elements.

Parameters:
handoff - the array
executor - the executor

createFromCopy

public static ParallelLongArray createFromCopy(long[] source,
                                               jsr166y.ForkJoinPool executor)
Creates a new ParallelLongArray using the given executor and initially holding copies of the given source elements.

Parameters:
source - the source of initial elements
executor - the executor

createFromCopy

public static ParallelLongArray createFromCopy(int size,
                                               long[] source,
                                               jsr166y.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.

Parameters:
source - the source of initial elements
size - the array size
executor - the executor

createEmpty

public static ParallelLongArray createEmpty(int size,
                                            jsr166y.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 asList() operations.

Parameters:
size - the array size
executor - the executor

getExecutor

public jsr166y.ForkJoinPool getExecutor()
Returns the executor used for computations

Returns:
the executor

apply

public void apply(Ops.LongProcedure procedure)
Applies the given procedure to elements

Overrides:
apply in class ParallelLongArrayWithLongMapping
Parameters:
procedure - the procedure

reduce

public long reduce(Ops.LongReducer reducer,
                   long base)
Returns reduction of elements

Overrides:
reduce in class ParallelLongArrayWithLongMapping
Parameters:
reducer - the reducer
base - the result for an empty array
Returns:
reduction

all

public ParallelLongArray all()
Returns a new ParallelLongArray holding all elements

Overrides:
all in class ParallelLongArrayWithLongMapping
Returns:
a new ParallelLongArray holding all elements

replaceWithMapping

public ParallelLongArray replaceWithMapping(Ops.LongOp op)
Replaces elements with the results of applying the given op to their current values.

Overrides:
replaceWithMapping in class ParallelLongArrayWithFilter
Parameters:
op - the op
Returns:
this (to simplify use in expressions)

replaceWithMappedIndex

public ParallelLongArray replaceWithMappedIndex(Ops.IntToLong op)
Replaces elements with the results of applying the given op to their indices.

Overrides:
replaceWithMappedIndex in class ParallelLongArrayWithFilter
Parameters:
op - the op
Returns:
this (to simplify use in expressions)

replaceWithMappedIndex

public ParallelLongArray replaceWithMappedIndex(Ops.IntAndLongToLong op)
Replaces elements with the results of applying the given mapping to each index and current element value

Overrides:
replaceWithMappedIndex in class ParallelLongArrayWithFilter
Parameters:
op - the op
Returns:
this (to simplify use in expressions)

replaceWithGeneratedValue

public ParallelLongArray replaceWithGeneratedValue(Ops.LongGenerator generator)
Replaces elements with the results of applying the given generator. For example, to fill the array with uniform random values, use replaceWithGeneratedValue(Ops.longRandom())

Overrides:
replaceWithGeneratedValue in class ParallelLongArrayWithFilter
Parameters:
generator - the generator
Returns:
this (to simplify use in expressions)

replaceWithValue

public ParallelLongArray replaceWithValue(long value)
Replaces elements with the given value.

Overrides:
replaceWithValue in class ParallelLongArrayWithFilter
Parameters:
value - the value
Returns:
this (to simplify use in expressions)

replaceWithMapping

public ParallelLongArray replaceWithMapping(Ops.BinaryLongOp combiner,
                                            ParallelLongArrayWithLongMapping other)
Replaces elements with results of applying op(thisElement, otherElement)

Overrides:
replaceWithMapping in class ParallelLongArrayWithFilter
Parameters:
other - the other array
combiner - the combiner
Returns:
this (to simplify use in expressions)

replaceWithMapping

public ParallelLongArray replaceWithMapping(Ops.BinaryLongOp combiner,
                                            long[] other)
Replaces elements with results of applying op(thisElement, otherElement)

Overrides:
replaceWithMapping in class ParallelLongArrayWithFilter
Parameters:
other - the other array
combiner - the combiner
Returns:
this (to simplify use in expressions)
Throws:
java.lang.ArrayIndexOutOfBoundsException - if other array has fewer elements than this array.

indexOf

public int indexOf(long target)
Returns the index of some element equal to given target, or -1 if not present

Overrides:
indexOf in class AbstractParallelAnyArray.LUPap
Parameters:
target - the element to search for
Returns:
the index or -1 if not present

binarySearch

public int binarySearch(long target)
Assuming this array is sorted, returns the index of an element equal to given target, or -1 if not present. If the array is not sorted, the results are undefined.

Overrides:
binarySearch in class AbstractParallelAnyArray.LUPap
Parameters:
target - the element to search for
Returns:
the index or -1 if not present

binarySearch

public 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. If the array is not sorted, the results are undefined.

Overrides:
binarySearch in class AbstractParallelAnyArray.LUPap
Parameters:
target - the element to search for
comparator - the comparator
Returns:
the index or -1 if not present

summary

public ParallelLongArray.SummaryStatistics summary(Ops.LongComparator comparator)
Returns summary statistics, using the given comparator to locate minimum and maximum elements.

Overrides:
summary in class ParallelLongArrayWithLongMapping
Parameters:
comparator - the comparator to use for locating minimum and maximum elements
Returns:
the summary.

summary

public ParallelLongArray.SummaryStatistics summary()
Returns summary statistics, using natural comparator

Overrides:
summary in class ParallelLongArrayWithLongMapping
Returns:
the summary.

min

public long min(Ops.LongComparator comparator)
Returns the minimum element, or Long.MAX_VALUE if empty

Overrides:
min in class ParallelLongArrayWithLongMapping
Parameters:
comparator - the comparator
Returns:
minimum element, or Long.MAX_VALUE if empty

min

public long min()
Returns the minimum element, or Long.MAX_VALUE if empty,

Overrides:
min in class ParallelLongArrayWithLongMapping
Returns:
minimum element, or Long.MAX_VALUE if empty

max

public long max(Ops.LongComparator comparator)
Returns the maximum element, or Long.MIN_VALUE if empty

Overrides:
max in class ParallelLongArrayWithLongMapping
Parameters:
comparator - the comparator
Returns:
maximum element, or Long.MIN_VALUE if empty

max

public long max()
Returns the maximum element, or Long.MIN_VALUE if empty

Overrides:
max in class ParallelLongArrayWithLongMapping
Returns:
maximum element, or Long.MIN_VALUE if empty

cumulate

public ParallelLongArray cumulate(Ops.LongReducer reducer,
                                  long base)
Replaces each element with the running cumulation of applying the given reducer. For example, if the contents are the numbers 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);

Overrides:
cumulate in class AbstractParallelAnyArray.LUPap
Parameters:
reducer - the reducer
base - the result for an empty array
Returns:
this (to simplify use in expressions)

precumulate

public 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. For example, if the contents are the numbers 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);

Overrides:
precumulate in class AbstractParallelAnyArray.LUPap
Parameters:
reducer - the reducer
base - the result for an empty array
Returns:
the total reduction

sort

public ParallelLongArray sort(Ops.LongComparator comparator)
Sorts the array. Unlike Arrays.sort, this sort does not guarantee that elements with equal keys maintain their relative position in the array.

Overrides:
sort in class AbstractParallelAnyArray.LUPap
Parameters:
comparator - the comparator to use
Returns:
this (to simplify use in expressions)

sort

public ParallelLongArray sort()
Sorts the array, assuming all elements are Comparable. Unlike Arrays.sort, this sort does not guarantee that elements with equal keys maintain their relative position in the array.

Overrides:
sort in class AbstractParallelAnyArray.LUPap
Returns:
this (to simplify use in expressions)
Throws:
java.lang.ClassCastException - if any element is not Comparable.

removeConsecutiveDuplicates

public ParallelLongArray removeConsecutiveDuplicates()
Removes consecutive elements that are equal, shifting others leftward, and possibly decreasing size. This method may be used after sorting to ensure that this ParallelLongArray contains a set of unique elements.

Returns:
this (to simplify use in expressions)

addAll

public ParallelLongArray addAll(long[] other)
Equivalent to asList().addAll but specialized for array arguments and likely to be more efficient.

Parameters:
other - the elements to add
Returns:
this (to simplify use in expressions)

addAll

public ParallelLongArray addAll(ParallelLongArrayWithLongMapping other)
Appends all (possibly bounded, filtered, or mapped) elements of the given ParallelDoubleArray, resizing and/or reallocating this array if necessary.

Parameters:
other - the elements to add
Returns:
this (to simplify use in expressions)

allUniqueElements

public ParallelLongArray allUniqueElements()
Returns a new ParallelLongArray containing only the unique elements of this array (that is, without any duplicates).

Overrides:
allUniqueElements in class ParallelLongArrayWithFilter
Returns:
the new ParallelLongArray

removeAll

public ParallelLongArray removeAll(Ops.LongPredicate selector)
Removes from the array all elements for which the given selector holds.

Parameters:
selector - the selector
Returns:
this (to simplify use in expressions)

hasAllEqualElements

public boolean hasAllEqualElements(ParallelLongArrayWithLongMapping other)
Returns true if all elements at the same relative positions of this and other array are equal.

Overrides:
hasAllEqualElements in class ParallelLongArrayWithFilter
Parameters:
other - the other array
Returns:
true if equal

sum

public long sum()
Returns the sum of elements

Overrides:
sum in class ParallelLongArrayWithLongMapping
Returns:
the sum of elements

cumulateSum

public ParallelLongArray cumulateSum()
Replaces each element with the running sum

Overrides:
cumulateSum in class AbstractParallelAnyArray.LUPap
Returns:
this (to simplify use in expressions)

precumulateSum

public long precumulateSum()
Replaces each element with its prefix sum

Overrides:
precumulateSum in class AbstractParallelAnyArray.LUPap
Returns:
the total sum

withBounds

public 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).

Overrides:
withBounds in class AbstractParallelAnyArray.LUPap
Parameters:
firstIndex - the lower bound (inclusive)
upperBound - the upper bound (exclusive)
Returns:
operation prefix

withFilter

public ParallelLongArrayWithFilter 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

Overrides:
withFilter in class AbstractParallelAnyArray.LUPap
Parameters:
selector - the selector
Returns:
operation prefix

withFilter

public ParallelLongArrayWithFilter withFilter(Ops.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

Overrides:
withFilter in class ParallelLongArrayWithFilter
Parameters:
selector - the selector
Returns:
operation prefix

withIndexedFilter

public ParallelLongArrayWithFilter withIndexedFilter(Ops.IntAndLongPredicate selector)
Returns an operation prefix that causes a method to operate only on elements for which the given indexed selector returns true

Overrides:
withIndexedFilter in class AbstractParallelAnyArray.LUPap
Parameters:
selector - the selector
Returns:
operation prefix

withMapping

public <U> ParallelLongArrayWithMapping<U> withMapping(Ops.LongToObject<? extends U> op)
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given op.

Overrides:
withMapping in class AbstractParallelAnyArray.LUPap
Parameters:
op - the op
Returns:
operation prefix

withMapping

public ParallelLongArrayWithLongMapping withMapping(Ops.LongOp op)
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given op.

Overrides:
withMapping in class AbstractParallelAnyArray.LUPap
Parameters:
op - the op
Returns:
operation prefix

withMapping

public ParallelLongArrayWithDoubleMapping withMapping(Ops.LongToDouble op)
Returns an operation prefix that causes a method to operate on mapped elements of the array using the given op.

Overrides:
withMapping in class AbstractParallelAnyArray.LUPap
Parameters:
op - the op
Returns:
operation prefix

withMapping

public <V,W,X> ParallelLongArrayWithMapping<W> withMapping(Ops.LongAndObjectToObject<? super V,? extends W> combiner,
                                                           ParallelArrayWithMapping<X,V> other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.

Overrides:
withMapping in class ParallelLongArrayWithLongMapping
Parameters:
combiner - the combiner
other - the other array
Returns:
operation prefix
Throws:
java.lang.IllegalArgumentException - if other array is a filtered view (all filters must precede all mappings).

withMapping

public <V> ParallelLongArrayWithMapping<V> withMapping(Ops.LongAndDoubleToObject<? 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.

Overrides:
withMapping in class ParallelLongArrayWithLongMapping
Parameters:
combiner - the combiner
other - the other array
Returns:
operation prefix
Throws:
java.lang.IllegalArgumentException - if other array is a filtered view (all filters must precede all mappings).

withMapping

public <V> ParallelLongArrayWithMapping<V> withMapping(Ops.LongAndLongToObject<? 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.

Overrides:
withMapping in class ParallelLongArrayWithLongMapping
Parameters:
combiner - the combiner
other - the other array
Returns:
operation prefix
Throws:
java.lang.IllegalArgumentException - if other array is a filtered view (all filters must precede all mappings).

withMapping

public <V,W> ParallelLongArrayWithDoubleMapping withMapping(Ops.LongAndObjectToDouble<? super V> combiner,
                                                            ParallelArrayWithMapping<W,V> other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.

Overrides:
withMapping in class ParallelLongArrayWithLongMapping
Parameters:
combiner - the combiner
other - the other array
Returns:
operation prefix
Throws:
java.lang.IllegalArgumentException - if other array is a filtered view (all filters must precede all mappings).

withMapping

public ParallelLongArrayWithDoubleMapping withMapping(Ops.LongAndDoubleToDouble combiner,
                                                      ParallelDoubleArrayWithDoubleMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.

Overrides:
withMapping in class ParallelLongArrayWithLongMapping
Parameters:
combiner - the combiner
other - the other array
Returns:
operation prefix
Throws:
java.lang.IllegalArgumentException - if other array is a filtered view (all filters must precede all mappings).

withMapping

public ParallelLongArrayWithDoubleMapping withMapping(Ops.LongAndLongToDouble combiner,
                                                      ParallelLongArrayWithLongMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.

Overrides:
withMapping in class ParallelLongArrayWithLongMapping
Parameters:
combiner - the combiner
other - the other array
Returns:
operation prefix
Throws:
java.lang.IllegalArgumentException - if other array is a filtered view (all filters must precede all mappings).

withMapping

public <V,W> ParallelLongArrayWithLongMapping withMapping(Ops.LongAndObjectToLong<? super V> combiner,
                                                          ParallelArrayWithMapping<W,V> other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.

Overrides:
withMapping in class ParallelLongArrayWithLongMapping
Parameters:
combiner - the combiner
other - the other array
Returns:
operation prefix
Throws:
java.lang.IllegalArgumentException - if other array is a filtered view (all filters must precede all mappings).

withMapping

public ParallelLongArrayWithLongMapping withMapping(Ops.LongAndDoubleToLong combiner,
                                                    ParallelDoubleArrayWithDoubleMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.

Overrides:
withMapping in class ParallelLongArrayWithLongMapping
Parameters:
combiner - the combiner
other - the other array
Returns:
operation prefix
Throws:
java.lang.IllegalArgumentException - if other array is a filtered view (all filters must precede all mappings).

withMapping

public ParallelLongArrayWithLongMapping withMapping(Ops.BinaryLongOp combiner,
                                                    ParallelLongArrayWithLongMapping other)
Returns an operation prefix that causes a method to operate on binary mappings of this array and the other array.

Overrides:
withMapping in class ParallelLongArrayWithLongMapping
Parameters:
combiner - the combiner
other - the other array
Returns:
operation prefix
Throws:
java.lang.IllegalArgumentException - if other array is a filtered view (all filters must precede all mappings).

withIndexedMapping

public <U> ParallelLongArrayWithMapping<U> withIndexedMapping(Ops.IntAndLongToObject<? 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.

Overrides:
withIndexedMapping in class AbstractParallelAnyArray.LUPap
Parameters:
mapper - the mapper
Returns:
operation prefix

withIndexedMapping

public ParallelLongArrayWithDoubleMapping withIndexedMapping(Ops.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.

Overrides:
withIndexedMapping in class AbstractParallelAnyArray.LUPap
Parameters:
mapper - the mapper
Returns:
operation prefix

withIndexedMapping

public ParallelLongArrayWithLongMapping withIndexedMapping(Ops.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.

Overrides:
withIndexedMapping in class AbstractParallelAnyArray.LUPap
Parameters:
mapper - the mapper
Returns:
operation prefix

iterator

public java.util.Iterator<java.lang.Long> iterator()
Returns an iterator stepping through each element of the array up to the current limit. This iterator does not support the remove operation. However, a full ListIterator supporting add, remove, and set operations is available via asList().

Returns:
an iterator stepping through each element.

asList

public java.util.List<java.lang.Long> asList()
Returns a view of this ParallelLongArray as a List. This List has the same structural and performance characteristics as 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.

Returns:
a list view

size

public int size()
Returns the effective size of the underlying array. The effective size is the current limit, if used (see setLimit(int)), or the length of the array otherwise.

Overrides:
size in class AbstractParallelAnyArray
Returns:
the effective size of array

getArray

public long[] getArray()
Returns the underlying array used for computations

Returns:
the array

get

public long get(int i)
Returns the element of the array at the given index

Parameters:
i - the index
Returns:
the element of the array at the given index

set

public void set(int i,
                long x)
Sets the element of the array at the given index to the given value

Parameters:
i - the index
x - the value

toString

public java.lang.String toString()
Equivalent to asList().toString()

Overrides:
toString in class java.lang.Object
Returns:
a string representation

setLimit

public final 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. Or, if the given limit is less than the length of the underlying array, causes computations to ignore elements past the given limit.

Parameters:
newLimit - the new upper bound
Throws:
java.lang.IllegalArgumentException - if newLimit less than zero.

replaceElementsParallelLongArrayWith

final void replaceElementsParallelLongArrayWith(long[] a)

resizeArray

final void resizeArray(int newCap)

insertElementAt

final void insertElementAt(int index,
                           long e)

appendElement

final void appendElement(long e)

insertSlotsAt

final void insertSlotsAt(int index,
                         int len)
Makes len slots available at index.


removeSlotAt

final void removeSlotAt(int index)

removeSlotsAt

final void removeSlotsAt(int fromIndex,
                         int toIndex)

seqIndexOf

final int seqIndexOf(long target)

seqLastIndexOf

final int seqLastIndexOf(long target)

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