Skip to content
This repository

The ParallelArray prototype is the central data structure around which RiverTrail programs are built. A ParallelArray data structure can be constructed using the following constructor forms:

Synopsis

ParallelArray();
ParallelArray(size, elementalFunction, arg1, ..., argN); 
ParallelArray(anArray);
ParallelArray(constructor, anArray);
ParallelArray(element0, element1, ..., elementN); 
ParallelArray(canvas);

Arguments

  • None: return a ParallelArray without elements.

  • Argument 0 is an Array and there are no more arguments: Use the values in the array to populate the new ParallelArray.

  • Argument 1 is an instance of Function (the elemental function), argument 0 is the size of the resulting array: Return a ParallelArray of size size where each value is the result of calling the elemental function with the index where its result goes and any remaining arg1, ..., argN arguments. If size is a number, then the index passed to the elemental function will be a number, as well. To support the creating of muli-dimensional arrays, size furthermore can be a vector. In such case, the index passed to the elemental function will be a vector, too.

  • Argument 0 is a function and there is one more argument: Construct a new parallel array as above but use the first argument as constructor for the internal data container; This form can be used to force the ParallelArray to hold its data as a typed array.

  • otherwise: Create a ParallelArray initialized to the elements passed in as arguments.

Discussion

To create a parallel array whose first element is an instanceOf function one must use the elemental function form and have the elemental function return the function. It also means that if one wants to create a ParallelArray with a single element that is an Array then it must use the elemental function form with a size of 1 and return the array from the elemental function.

Returns

A freshly minted ParallelArray

Examples

<…> is used to indicate a ParallelArray in these examples it is not syntactical sugar actually available to the program.

    pa1 = new ParallelArray([ [0,1], [2,3], [4,5] ]); // <<0,1>, <2,3>, <4.5>>
    pa2 = new ParallelArray(pa1);                     // <<0,1>, <2,3>, <4.5>>
    new ParallelArray(<0,1>, <2,3>);                  // <<0,1>,<2,3>>
    new ParallelArray([ [0,1],[2] ])                   // <<0,1>, <2>>
    new ParallelArray([<0,1>,<2>]);                   // <<0,1>, <2>>
    new ParallelArray(3, 
            function(i){return [i, i+1];});           // <<0,1><1,2><2,3>>
    new ParallelArray([3,2], 
            function(iv){return iv[0]*iv[1];});       // <<0,0><0,1><0,2>>
    new ParallelArray(canvas);                        // CanvasPixelArray

Methods

Something went wrong with that request. Please try again.