Class Array<T>
Object
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
containingcount
copies ofvalue
. init (count :
,Int generator :
)(Int)=&>(T) - Creates a new
Array
containingcount
values produced bygenerator
.
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 fromindex
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 fromindex + 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 anArray
. filter (predicate :
):(T)=&>(Bit) Array<T> - As
ListView.filter((T)=&>(Bit))
, but returns anArray
. combine<U> (other :
):ListView<U> Array<(frost.collections.Array.T, frost.collections.Array.combine.U)> - As
ListView.combine(ListView<U>)
, but returns anArray
. combine<U, V> (other :
,ListView<U> f :
):(T, U)=>(V) Array<V> - As
ListView.combine(ListView<U>, (T, U)=>(V))
, but returns anArray
. combine<U, V> (other :
,ListView<U> f :
):(T, U)=&>(V) Array<V> - As
ListView.combine(ListView<U>, (T, U)=&>(V))
, but returns anArray
. sort (greater :
):(T, T)=>(Bit) Array<T> - As
ListView.sort
, but returns anArray
.
removeLast()
map((T)=&>(U)):Array<U>
map((T)=>(U)):Array<U>
apply((T)=&>())
fold((T, T)=&>(T), T):T
fold((T, T)=>(T), T):T
fold((T, T)=&>(T)):T
fold((T, T)=>(T)):T
join(String):String
join():String
sort((T, T)=>(Bit)):ListView<T>
combinations(Int):Iterator<ListView<T>>
combine(ListView<U>, (T, U)=&>(V)):ListView<V>
combine(ListView<U>, (T, U)=>(V)):ListView<V>
combine(ListView<U>):ListView<(frost.collections.ListView.T, frost.collections.ListView.combine.U)>
filter((T)=&>(Bit)):ListView<T>
filter((T)=>(Bit)):ListView<T>
[](SteppedRange<Int?, Int>):ListView<T>
[](Range<Int?>):ListView<T>
[](Range<Int>):ListView<T>
sortInPlace((T, T)=>(Bit))
mapInPlace((T)=>(T))
filterInPlace((T)=>(Bit))
[]:=(Range<Int?>, ListView<T>)
[]:=(Range<Int>, ListView<T>)
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:
-
- value of typecapacity Int
init
(other :CollectionView<T>
)
Creates a new Array
containing all the elements in another collection.
- Parameters:
-
- value of typeother CollectionView<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:
-
- value of typecount Int
- value of typegenerator (Int)=&>(T)
Instance Methods
Returns an entry from this array.
- Parameters:
-
- value of typeindex 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:
-
- value of typer 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:
-
- value of typer Range<Int?>
Replaces an element in this array with a new element.
- Overrides:
- frost.collections.ListWriter.[]:=
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 of typevalue 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:
-
- value of typec CollectionView<T>
- Overrides:
- frost.collections.CollectionWriter.addAll
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:
-
- value of typepredicate (T)=>(Bit)
method filter
(predicate :(T)=&>(Bit)
):Array<T>
As ListView.filter((T)=&>(Bit))
, but returns an Array
.
- Parameters:
-
- value of typepredicate (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:
-
- value of typeother 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:
-
- value of typeother ListView<U>
- value of typef (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:
-
- value of typeother ListView<U>
- value of typef (T, U)=&>(V)
method sort
(greater :(T, T)=>(Bit)
):Array<T>
As ListView.sort
, but returns an Array
.
- Parameters:
-
- value of typegreater (T, T)=>(Bit)