frost.collections

Class Array<T>

    └ Object

Implemented Interfaces:

Standard implementation of the List interface. Array is a resizable random-access array, featuring constant time reads and writes. Appending new elements to the array can be expensive, as it may require the backing store to be increased in size which in turn may require a memory copy.

Particularly for bigger arrays, it is best to avoid this expensive size increase by pre-allocating the array with the expected number of elements it will contain using init(Int).

Source Code:
View Source

Initializer Summary

init()
Creates a new, empty Array.
init(capacity:Int)
Creates a new, empty Array with the specified maximum capacity.
init(other:CollectionView<T>)
Creates a new Array containing all the elements in another collection.
init(count:Int, value:T)
Creates a new Array containing count copies of value.
init(count:Int, generator:(Int)=&>(T))
Creates a new Array containing count values produced by generator.
Inherited Fields:

Instance Method Summary

-- index operator --
[](index:Int):T
Returns an entry from this array.
-- index operator --
[](r:Range<Int>):Array<T>
Returns a new array containing a slice of this array.
-- index operator --
[](r:Range<Int?>):Array<T>
Returns a new array containing a slice of this array.
-- indexed assignment operator --
[]:=(index:Int, value:T)
Replaces an element in this array with a new element.
insert(index:Int, value:T)
Inserts a new element at index, moving all elements from index to the end of the list out of the way to make room for it.
add(value:T)
Adds a new element to the collection.
addAll(c:CollectionView<T>)
Adds all elements in c to this collection.
removeIndex(index:Int):T
Removes the element at index, moving all elements from index + 1 to the end of the list down one index to fill in the "hole" created by the deletion.
clear()
Removes all elements in the collection.
filter(predicate:(T)=>(Bit)):Array<T>
As ListView.filter((T)=>(Bit)), but returns an Array.
filter(predicate:(T)=&>(Bit)):Array<T>
As ListView.filter((T)=&>(Bit)), but returns an Array.
combine<U>(other:ListView<U>):Array<(frost.collections.Array.T, frost.collections.Array.combine.U)>
As ListView.combine(ListView<U>), but returns an Array.
combine<U, V>(other:ListView<U>, f:(T, U)=>(V)):Array<V>
As ListView.combine(ListView<U>, (T, U)=>(V)), but returns an Array.
combine<U, V>(other:ListView<U>, f:(T, U)=&>(V)):Array<V>
As ListView.combine(ListView<U>, (T, U)=&>(V)), but returns an Array.
sort(greater:(T, T)=>(Bit)):Array<T>
As ListView.sort, but returns an Array.
Inherited Methods:

Initializers

init ()

Creates a new, empty Array.

init (capacity:Int)

Creates a new, empty Array with the specified maximum capacity. The Array will allocate enough memory to hold capacity elements at the time of its creation.

Parameters:
capacity - value of type Int
init (other:CollectionView<T>)

Creates a new Array containing all the elements in another collection.

Parameters:
other - value of type CollectionView<T>
init (count:Int,
 value:T)

Creates a new Array containing count copies of value.

Parameters:
count - value of type Int
value - value of type T
init (count:Int,
 generator:(Int)=&>(T))

Creates a new Array containing count values produced by generator. generator is called count times, starting with the parameter 0 and ending with count - 1.

Parameters:
count - value of type Int
generator - value of type (Int)=&>(T)

Instance Methods

-- index operator --
@override
function [] (index:Int
):T

Returns an entry from this array.

Parameters:
index - value of type Int
Overrides:
frost.collections.ListView.[]
-- index operator --
function [] (r:Range<Int>
):Array<T>

Returns a new array containing a slice of this array. The new array is an independent shallow copy: they contain the same elements, so modifying to the elements will be visible in both arrays, but modifications to the arrays themselves (adding / removing / replacing elements) will not.

Parameters:
r - value of type Range<Int>
-- index operator --
function [] (r:Range<Int?>
):Array<T>

Returns a new array containing a slice of this array. The new array is an independent shallow copy: they contain the same elements, so modifying to the elements will be visible in both arrays, but modifications to the arrays themselves (adding / removing / replacing elements) will not.

Parameters:
r - value of type Range<Int?>
-- indexed assignment operator --
@override
method []:= (index:Int,
 value:T)

Replaces an element in this array with a new element.

Parameters:
index - value of type Int
value - value of type T
Overrides:
frost.collections.ListWriter.[]:=
@override
method insert (index:Int,
 value:T)

Inserts a new element at index, moving all elements from index to the end of the list out of the way to make room for it. Inserting with an index equal to count is equivalent to calling add.

Parameters:
index - the location at which to insert
value - the new value
Overrides:
frost.collections.ListWriter.insert
@override
method add (value:T)

Adds a new element to the collection. The exact semantics of add - does it add to the end of the collection, or an arbitrary location? does it always actually add the element, or sometimes leave the collection unmodified? - are defined by the collection implementation.

Parameters:
value - value of type T
Overrides:
frost.collections.CollectionWriter.add
@override
method addAll (c:CollectionView<T>)

Adds all elements in c to this collection. The default implementation simply calls add for each element in c, in iteration order.

Parameters:
c - value of type CollectionView<T>
Overrides:
frost.collections.CollectionWriter.addAll
@override
method removeIndex (index:Int
):T

Removes the element at index, moving all elements from index + 1 to the end of the list down one index to fill in the "hole" created by the deletion.

Parameters:
index - the index to remove
Returns:
the value which was removed
Overrides:
frost.collections.ListWriter.removeIndex
@override
method clear ()

Removes all elements in the collection.

Overrides:
frost.collections.CollectionWriter.clear
function filter (predicate:(T)=>(Bit)
):Array<T>

As ListView.filter((T)=>(Bit)), but returns an Array.

Parameters:
predicate - value of type (T)=>(Bit)
method filter (predicate:(T)=&>(Bit)
):Array<T>

As ListView.filter((T)=&>(Bit)), but returns an Array.

Parameters:
predicate - value of type (T)=&>(Bit)
@pre(count = other.count)
function combine<U> (other:ListView<U>
):Array<(frost.collections.Array.T, frost.collections.Array.combine.U)>

As ListView.combine(ListView<U>), but returns an Array.

Parameters:
other - value of type ListView<U>
@pre(count = other.count)
function combine<U, V> (other:ListView<U>,
 f:(T, U)=>(V)
):Array<V>

As ListView.combine(ListView<U>, (T, U)=>(V)), but returns an Array.

Parameters:
other - value of type ListView<U>
f - value of type (T, U)=>(V)
@pre(count = other.count)
method combine<U, V> (other:ListView<U>,
 f:(T, U)=&>(V)
):Array<V>

As ListView.combine(ListView<U>, (T, U)=&>(V)), but returns an Array.

Parameters:
other - value of type ListView<U>
f - value of type (T, U)=&>(V)
method sort (greater:(T, T)=>(Bit)
):Array<T>

As ListView.sort, but returns an Array.

Parameters:
greater - value of type (T, T)=>(Bit)