Array#
Provides mutable array types that store their elements on the heap rather than in registers or the stack.
- type
Array
-
An opaque type of supertype
Struct
.- inline
__==
( ... ) - fn
__@
( self index ) -
Implements support for the
@
operator. Returns a view reference to the element atindex
of arrayself
. - inline
__as
( cls T ) -
Implements support for the
as
operator. Arrays can be cast toGenerator
, or directly passed tofor
. - fn
__copy
( self ) -
Implements support for the
copy
operation. - inline
__countof
( self ) -
Implements support for the
countof
operator. Returns the current number of elements stored inself
as a value ofusize
type. - fn
__drop
( self ) -
Implements support for freeing the array's memory when it goes out of scope.
- inline
__imply
( cls T ) -
Implements support for pointer casts, to pass the array to C functions for example.
- inline
__typecall
( cls element-type capacity ) -
Construct a mutable array type of
element-type
with a variable or fixed maximum capacity.If
capacity
is defined, then it specifies the maximum number of array elements permitted. If it is undefined, then an initial capacity of 16 elements is assumed, which is doubled whenever it is exceeded, allowing for an indefinite number of elements. - fn
append
( self value ) -
Append
value
as an element to the arrayself
and return a reference to the new element. When thearray
is ofGrowingArray
type, this operation will transparently resize the array's storage. - fn
clear
( self ) -
Clear the array and reset its element count to zero. This will drop all elements that have been previously contained by the array.
- inline
emplace-append
( self args... ) -
Construct a new element with arguments
args...
directly in a newly assigned slot of arrayself
. When thearray
is ofGrowingArray
type, this operation will transparently resize the array's storage. - inline
emplace-append-many
( self size args... ) -
Construct a new element with arguments
args...
directly in a newly assigned slot of arrayself
. When thearray
is ofGrowingArray
type, this operation will transparently resize the array's storage. - type
insert
-
Insert
value
atindex
into the arrayself
and return a reference to the new element. When thearray
is ofGrowingArray
type, this operation will transparently resize the array's storage. This operation offsets the index of each following element by 1. If index is omitted,insert
operates likeappend
. - fn
last
( self ) - fn
pop
( self ) -
Remove element with highest index from array
self
and return it. - inline
predicated-sort
( self predicate ... ) -
Sort elements of array
self
from smallest to largest, either using the<
operator supplied by the element type, or by using the predicate supplied by the callablepredicate
, which takes two arguments and is expected to return true if the first argument is smaller than the second one. - fn
remove
( self index ) -
Remove element at index from array
self
and return it. This operation offsets the index of each following element by -1. - fn
resize
( self count args... ) -
Resize the array to the specified count. Items are appended or removed to meet the desired count.
- inline
sort
( self key ... ) -
Sort elements of array
self
from smallest to largest, either using the<
operator supplied by the element type, or by using the key supplied by the callablekey
, which is expected to return a comparable value for each element value supplied. - fn
swap
( self a b ) -
Safely swap the contents of two indices.
- inline
- type
FixedArray
-
An opaque type of supertype
Array
.- fn
__repr
( self ) -
Implements support for the
repr
operation. - inline
__typecall
( cls opts... ) - inline
capacity
( self ) -
Returns the maximum capacity of array
self
, which is fixed. - fn
reserve
( self count ) -
Internally used by the type. Ensures that array
self
can hold at leastcount
elements. A fixed array will raise an assertion when its capacity has been exceeded.
- fn
- type
GrowingArray
-
An opaque type of supertype
Array
.- fn
__repr
( self ) -
Implements support for the
repr
operation. - inline
__typecall
( cls opts... ) - inline
capacity
( self ) -
Returns the current maximum capacity of array
self
. - fn
reserve
( self count ) -
Internally used by the type. Ensures that array
self
can hold at leastcount
elements. A growing array will always attempt to comply.
- fn