ArrayedCollection:
Filter:
Classes | Collections > Ordered

ArrayedCollection : SequenceableCollection : Collection : Object

Abstract superclass of Collections of fixed maximum size
Subclasses: Array, RawArray

Description

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.

Class Methods

ArrayedCollection.newClear(indexedSize: 0)

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.

ArrayedCollection.with( ... args)

From superclass: Collection

Create a new ArrayedCollection whose slots are filled with the given arguments.

ArrayedCollection.series(size, start: 0, step: 1)

From superclass: SequenceableCollection

Fill an ArrayedCollection with an arithmetic series.

ArrayedCollection.geom(size, start, grow)

From superclass: SequenceableCollection

Fill an ArrayedCollection with a geometric series.

ArrayedCollection.iota( ... sizes)

Fills an ArrayedCollection with a counter. See J concepts in SC for more examples.

Inherited class methods

Instance Methods

.size

Return the number of elements the ArrayedCollection.

.maxSize

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.

.isRectangular

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:

.at(index)

Return the item at index. The index can also be an array of indices to extract the specified elements. Array is its syntactic shortcut.

.clipAt(index)

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.

.wrapAt(index)

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.

.foldAt(index)

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(name, bounds, discrete: false, numChannels, minval, maxval, separately: true, parent)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Math/PlotView.sc

Plot values in a GUI window. See plot for more details. When the receiver contains nil items, the plot fails with an error.

.swap(i, j)

Swap the values at indices i and j.

.put(index, item)

Put item at index, replacing what is there.

.clipPut(index, item)

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.

.wrapPut(index, item)

Same as -put, but values for index greater than the ArrayedCollection instance size minus one will be wrapped around to 0.

.foldPut(index, item)

Same as -put, but values for index greater than the ArrayedCollection instance size minus one will be folded back.

.putEach(keys, values)

Put the values in the corresponding indices given by keys. If one of the two argument arrays is longer then it will wrap.

.indexOf(item)

Return the first index containing an item which matches item. Elements are checked for identity (not for equality).

.includes(item)

Return a boolean indicating whether the collection contains anything matching item. Elements are checked for identity (not for equality).

.indexOfGreaterThan(val)

Return the first index containing an item which is greater than item.

.removeAt(index)

Remove and return the element at index, shrinking the size of the ArrayedCollection.

.takeAt(index)

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.

.takeThese(func)

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.

.add(item)

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.

.addAll(aCollection)

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.

.extend(size, item)

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.

.fill(value)

Inserts the item into the contents of the receiver.

NOTE: the difference between this and Collection's *fill.

.insert(index, item)

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.

.move(fromIndex, toIndex)

Moves an item from one position to another.

Arguments:

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.

.addFirst(item)

Inserts the item before the contents of the receiver, possibly returning a new collection.

.pop

Remove and return the last element of the ArrayedCollection.

.grow(sizeIncrease)

Increase the size of the ArrayedCollection by sizeIncrease number of slots, possibly returning a new collection.

.growClear(sizeIncrease)

Increase the size of the ArrayedCollection by sizeIncrease number of slots, returning a new collection with Nils in the added slots.

.copyRange(start, end)

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.

WARNING: 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.

.copySeries(first, second, last)

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]

NOTE:  If the intent is to copy forward, and you are calculating start and end indices such that end may be less than start, copyRange is not recommended. In this case, copySeries or the shortcut syntax x[a..b] is recommended because it will adapt to use a positive or negative step as needed.

.seriesFill(start, step)

Fill the receiver with an arithmetic progression. The first element will be start, the second start + step, the third start + step + step ...

.putSeries(first, second, last, value)

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

++(anArray)

Concatenate the contents of the two collections into a new ArrayedCollection.

.reverse

Return a new ArrayedCollection whose elements are reversed.

.do(function)

Iterate over the elements in order, calling the function for each element. The function is passed two arguments, the element and an index.

.reverseDo(function)

Iterate over the elements in reverse order, calling the function for each element. The function is passed two arguments, the element and an index.

.collect(function)

From superclass: Collection

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.

.deepCollect(depth: 1, function, index: 0, rank: 0)

The same as -collect, but can look inside sub-arrays up to the specified depth.

.windex

Interprets the array as a list of probabilities which should sum to 1.0 and returns a random index value based on those probabilities.

.normalizeSum

Returns the Array resulting from :

so that the array will sum to 1.0.

This is useful for using with windex or wchoose.

.normalize(min: 0.0, max: 1.0)

Returns a new Array with the receiver items normalized between min and max.

.perfectShuffle

Returns a copy of the receiver with its items split into two equal halves, then reconstructed by interleaving the two halves.

NOTE: the size of the collection should be even, otherwise the item directly in the middle of the collection will be lost in the shuffle.

.performInPlace(selector, from, to, argList)

Performs a method in place, within a certain region [from..to], returning the same array.

.rank

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.

.shape

Returns an array describing the dimension of each nested array. Requires -isRectangular as a precondition.

.reshape( ... shape)

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.

.find(sublist, offset: 0)

From superclass: SequenceableCollection

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

.replace(find, replace)

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 :

.asRandomTable(size)

Return an integral table that can be used to generate random numbers with a specified distribution. (see Randomness helpfile for a more detailed example)

.tableRand

Returns a new random number from a random table.

.msgSize

Return the size of an osc message in bytes

.bundleSize

Return the size of an osc bundle in bytes

.asciiPlot

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

Inherited instance methods

Undocumented instance methods

.addIfNotNil(item)

.asArray

.atDec(index, dec: 1)

.atInc(index, inc: 1)

.atModify(index, function)

.bubble(depth: 0, levels: 1)

.clipExtend(length)

.clumpBundles

.deepDo(depth: 1, function, index: 0, rank: 0)

.getSlots

.indexedSize

.isArray

.overWrite(aCollection, pos: 0)

.prBundleSize

.reshapeLike(another, indexing: 'wrapAt')

.setSlots(array)

.slice( ... cuts)

.slotAt(index)

.slotIndex(key)

.slotKey(index)

.slotPut(index, value)

.slotSize

.unbubble(depth: 0, levels: 1)