ArrayedCollection is an abstract class, a subclass of SequenceableCollections whose elements are held in a vector of slots. Instances of ArrayedCollection have a fixed maximum size beyond which they may not grow.
Its principal subclasses are Array (for holding objects), and RawArray, from which Int8Array, FloatArray, Signal etc. inherit.
Creates a new instance with indexedSize indexable slots. The slots are filled with Nil, zero or something else appropriate to the type of indexable slots in the object.
Create a new ArrayedCollection whose slots are filled with the given arguments.
Fill an ArrayedCollection with an arithmetic series.
Fill an ArrayedCollection with a geometric series.
Fills an ArrayedCollection with a counter. See J concepts in SC for more examples.
Return the number of elements the ArrayedCollection.
Return the maximum number of elements the ArrayedCollection can hold. For example, Arrays may initialise themselves with a larger capacity than the number of elements added.
Returns true if all nested sub arrays are the same size and all elements have the same depth. This is a requirement of several nested array algorithms and formats, notably multichannel audio files.
Example:
Return the item at index. The index can also be an array of indices to extract the specified elements. Array is its syntactic shortcut.
Similar to -at, but guarantees that any value for index is valid by clipping values outside the collection's bounds. Values greater than size - 1
are clipped to that last index, and values below 0
(negative) are clipped to 0. The index can also be an array of indices to extract the specified elements. SequenceableCollection: -|@| is its syntactic shortcut.
Similar to -at, but guarantees that any value for index is valid by wrapping values outside the collection's bounds. If the index exceeds size - 1
, it wraps back around to 0
. Similarly, if the index is below 0
(negative), it wraps to access elements from the end of the collection. this.wrapAt(index)
is equivalent to this.at(index mod: size)
, ensuring the index is always within the valid range of the collection. The index can also be an array of indices to extract the specified elements. SequenceableCollection: -@@ is its syntactic shortcut.
Similar to -at, but guarantees that any value for index is valid by reflecting values outside the collection's bounds. Values greater than size - 1
are reflected back toward lower indices. Similarly, if the index is below 0
(negative), it folds in the opposite direction. This creates a symmetrical mapping of any index within the collection's boundaries. The index can also be an array of indices to extract the specified elements. SequenceableCollection: -@|@ is its syntactic shortcut.
Plot values in a GUI window. See plot for more details. When the receiver contains nil
items, the plot fails with an error.
Swap the values at indices i and j.
Put item at index, replacing what is there.
Same as -put, but values for index greater than the ArrayedCollection instance size minus one will be clipped to size - 1
, which is the last index.
Same as -put, but values for index greater than the ArrayedCollection instance size minus one will be wrapped around to 0.
Same as -put, but values for index greater than the ArrayedCollection instance size minus one will be folded back.
Put the values in the corresponding indices given by keys. If one of the two argument arrays is longer then it will wrap.
Return the first index containing an item which matches item. Elements are checked for identity (not for equality).
Return a boolean indicating whether the collection contains anything matching item. Elements are checked for identity (not for equality).
Return the first index containing an item which is greater than item.
Remove and return the element at index, shrinking the size of the ArrayedCollection.
Similar to -removeAt, but does not maintain the order of the items following the one that was removed. Instead, the last item is placed into the position of the removed item and the array's size decreases by one.
Removes all items in the receiver for which the func answers true. The function is passed two arguments, the item and an integer index. Note that order is not preserved. See -takeAt.
Adds an item to an ArrayedCollection if there is space. This method may return a new ArrayedCollection. For this reason, you should always assign the result of add to a variable - never depend on add
changing the receiver.
Adds all the elements of aCollection to the contents of the receiver. This method may return a new ArrayedCollection. For this reason, you should always assign the result of addAll
to a variable - never depend on add changing the receiver.
Extends the object to match size by adding a number of items. If size is less than receiver size then truncate. This method may return a new ArrayedCollection. For this reason, you should always assign the result of extend
to a variable - never depend on add changing the receiver.
Inserts the item into the contents of the receiver.
Inserts the item into the contents of the receiver. This method may return a new ArrayedCollection. For this reason, you should always assign the result of insert
to a variable - never depend on add changing the receiver.
Moves an item from one position to another.
fromIndex |
The position in the array from which the element is removed. |
toIndex |
The position in the array before which the element is inserted again. |
Inserts the item before the contents of the receiver, possibly returning a new collection.
Remove and return the last element of the ArrayedCollection.
Increase the size of the ArrayedCollection by sizeIncrease number of slots, possibly returning a new collection.
Increase the size of the ArrayedCollection by sizeIncrease number of slots, returning a new collection with Nils in the added slots.
Return a new ArrayedCollection which is a copy of the indexed slots of the receiver from start to end. If end < start, an empty ArrayedCollection is returned.
x.copyRange(a, b)
is not equivalent to x[a..b]
. The latter compiles to -copySeries, which has different behavior when end < start. See NOTE in -copySeries.Return a new ArrayedCollection consisting of the values starting at first, then every step of the distance between first and second, up until last. If second is nil
, a step of 1 or -1 is used as appropriate.
x.copySeries(a, nil, c)
is equivalent to x[a..c]
, and x.copySeries(a, b, c)
is equivalent to x[a, b..c]
Fill the receiver with an arithmetic progression. The first element will be start, the second start + step, the third start + step + step ...
Put value at every index starting at first, then every step of the distance between first and second, up until last. x.putSeries(a, b, c, val)
can also be written as x[a, b..c] = val
Concatenate the contents of the two collections into a new ArrayedCollection.
Return a new ArrayedCollection whose elements are reversed.
Iterate over the elements in order, calling the function for each element. The function is passed two arguments, the element and an index.
Iterate over the elements in reverse order, calling the function for each element. The function is passed two arguments, the element and an index.
Answer a new collection which consists of the results of function evaluated for each item in the collection. The function is passed two arguments, the item and an integer index. See Collection helpfile for examples.
The same as -collect, but can look inside sub-arrays up to the specified depth.
Interprets the array as a list of probabilities which should sum to 1.0 and returns a random index value based on those probabilities.
Returns the Array resulting from :
so that the array will sum to 1.0.
This is useful for using with windex or wchoose.
Returns a new Array with the receiver items normalized between min and max.
Returns a copy of the receiver with its items split into two equal halves, then reconstructed by interleaving the two halves.
Performs a method in place, within a certain region [from..to], returning the same array.
Returns the number of dimensions of the collection. rank
inspects the size of the left-most elements of sub-arrays only, i.e. it's assumed that the collection -isRectangular, so subarrays of mismatched sizes may not return an expected result. A single value has a rank of 0
. An empty array has a rank of 1
.
Returns an array describing the dimension of each nested array. Requires -isRectangular as a precondition.
For a multidimensional array, rearranges the data using the desired number of elements along each dimension. The data may be extended using Array: -wrapExtend if needed. This will always return a rectangular array, see -isRectangular.
Finds the starting index of a number of elements contained in the array. This method expects a collection as an argument. So for finding only one element, have a look at SequenceableCollection: -indexOfEqual. Elements are checked for equality (not for identity).
Return a new array in which a number of elements have been replaced by another. Elements are checked for equality (not for identity).
this method is inherited by String :
Return an integral table that can be used to generate random numbers with a specified distribution. (see Randomness helpfile for a more detailed example)
Returns a new random number from a random table.
Return the size of an osc message in bytes
Return the size of an osc bundle in bytes
For an ArrayedCollection containing numbers (e.g. audio data) this renders a plot in the post window using asterisks and spaces (works best if you use a monospace font in your post window).