Array [Src] [A: A]
Contiguous, resizable memory to store elements of type A.
class ref Array[A: A] is
Seq[A] ref
Implements
- Seq[A] ref
Constructors
create [Src]
Create an array with zero elements, but space for len elements.
new ref create(
len: USize val = seq)
: Array[A] ref^
Parameters
- len: USize val = seq
Returns
- Array[A] ref^
init [Src]
Create an array of len elements, all initialised to the given value.
new ref init(
from: A^,
len: USize val)
: Array[A] ref^
Parameters
- from: A^
- len: USize val
Returns
- Array[A] ref^
from_cpointer [Src]
Create an array from a C-style pointer and length. The contents are not copied.
new ref from_cpointer(
ptr: Pointer[A] ref,
len: USize val,
alloc: USize val = seq)
: Array[A] ref^
Parameters
Returns
- Array[A] ref^
Public Functions
cpointer [Src]
Return the underlying C-style pointer.
fun box cpointer(
offset: USize val = seq)
: Pointer[A] tag
Parameters
- offset: USize val = seq
Returns
- Pointer[A] tag
size [Src]
The number of elements in the array.
fun box size()
: USize val
Returns
- USize val
space [Src]
The available space in the array.
fun box space()
: USize val
Returns
- USize val
reserve [Src]
Reserve space for len elements, including whatever elements are already in the array. Array space grows geometrically.
fun ref reserve(
len: USize val)
: None val
Parameters
- len: USize val
Returns
- None val
compact [Src]
Try to remove unused space, making it available for garbage collection. The request may be ignored.
fun ref compact()
: None val
Returns
- None val
undefined [Src] [optional B: (A & Real[B] val & (I8 val | I16 val | I32 val | I64 val | I128 val | ILong val | ISize val | U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val | F32 val | F64 val))]
Resize to len elements, populating previously empty elements with random memory. This is only allowed for an array of numbers.
fun ref undefined[optional B: (A & Real[B] val & (I8 val | I16 val | I32 val |
I64 val | I128 val | ILong val |
ISize val | U8 val | U16 val |
U32 val | U64 val | U128 val |
ULong val | USize val | F32 val |
F64 val))](
len: USize val)
: None val
Parameters
- len: USize val
Returns
- None val
apply [Src]
Get the i-th element, raising an error if the index is out of bounds.
fun box apply(
i: USize val)
: this->A ?
Parameters
- i: USize val
Returns
- this->A ?
update [Src]
Change the i-th element, raising an error if the index is out of bounds.
fun ref update(
i: USize val,
value: A)
: A^ ?
Parameters
- i: USize val
- value: A
Returns
- A^ ?
insert [Src]
Insert an element into the array. Elements after this are moved up by one index, extending the array. An out of bounds index raises an error.
fun ref insert(
i: USize val,
value: A)
: None val ?
Parameters
- i: USize val
- value: A
Returns
- None val ?
delete [Src]
Delete an element from the array. Elements after this are moved down by one index, compacting the array. An out of bounds index raises an error. The deleted element is returned.
fun ref delete(
i: USize val)
: A^ ?
Parameters
- i: USize val
Returns
- A^ ?
truncate [Src]
Truncate an array to the given length, discarding excess elements. If the array is already smaller than len, do nothing.
fun ref truncate(
len: USize val)
: None val
Parameters
- len: USize val
Returns
- None val
trim_in_place [Src]
Trim the array to a portion of itself, covering from
until to
.
Unlike slice, the operation does not allocate a new array nor copy elements.
fun ref trim_in_place(
from: USize val = seq,
to: USize val = seq)
: None val
Parameters
Returns
- None val
trim [Src]
Return a shared portion of this array, covering from
until to
.
Both the original and the new array are immutable, as they share memory.
The operation does not allocate a new array pointer nor copy elements.
fun val trim(
from: USize val = seq,
to: USize val = seq)
: Array[A] val
Parameters
Returns
- Array[A] val
copy_to [Src]
Copy len elements from this(src_idx) to dst(dst_idx).
fun box copy_to(
dst: Array[this->A!] ref,
src_idx: USize val,
dst_idx: USize val,
len: USize val)
: None val
Parameters
Returns
- None val
remove [Src]
Remove n elements from the array, beginning at index i.
fun ref remove(
i: USize val,
n: USize val)
: None val
Parameters
Returns
- None val
clear [Src]
Remove all elements from the array.
fun ref clear()
: None val
Returns
- None val
push [Src]
Add an element to the end of the array.
fun ref push(
value: A)
: None val
Parameters
- value: A
Returns
- None val
pop [Src]
Remove an element from the end of the array. The removed element is returned.
fun ref pop()
: A^ ?
Returns
- A^ ?
unshift [Src]
Add an element to the beginning of the array.
fun ref unshift(
value: A)
: None val
Parameters
- value: A
Returns
- None val
shift [Src]
Remove an element from the beginning of the array. The removed element is returned.
fun ref shift()
: A^ ?
Returns
- A^ ?
append [Src]
Append the elements from a sequence, starting from the given offset.
fun ref append(
seq: (ReadSeq[A] box & ReadElement[A^] box),
offset: USize val = seq,
len: USize val = seq)
: None val
Parameters
- seq: (ReadSeq[A] box & ReadElement[A^] box)
- offset: USize val = seq
- len: USize val = seq
Returns
- None val
concat [Src]
Add len iterated elements to the end of the array, starting from the given offset.
fun ref concat(
iter: Iterator[A^] ref,
offset: USize val = seq,
len: USize val = seq)
: None val
Parameters
Returns
- None val
find [Src]
Find the nth
appearance of value
from the beginning of the array,
starting at offset
and examining higher indices, and using the supplied
predicate
for comparisons. Returns the index of the value, or raise an
error if the value isn't present.
By default, the search starts at the first element of the array, returns
the first instance of value
found, and uses object identity for
comparison.
fun box find(
value: A!,
offset: USize val = seq,
nth: USize val = seq,
predicate: {(box->A!, box->A!): Bool}[A] val = seq)
: USize val ?
Parameters
- value: A!
- offset: USize val = seq
- nth: USize val = seq
- predicate: {(box->A!, box->A!): Bool}[A] val = seq
Returns
- USize val ?
contains [Src]
Returns true if the array contains value
, false otherwise.
fun box contains(
value: A!,
predicate: {(box->A!, box->A!): Bool}[A] val = seq)
: Bool val
Parameters
- value: A!
- predicate: {(box->A!, box->A!): Bool}[A] val = seq
Returns
- Bool val
rfind [Src]
Find the nth
appearance of value
from the end of the array, starting at
offset
and examining lower indices, and using the supplied predicate
for
comparisons. Returns the index of the value, or raise an error if the value
isn't present.
By default, the search starts at the last element of the array, returns the
first instance of value
found, and uses object identity for comparison.
fun box rfind(
value: A!,
offset: USize val = seq,
nth: USize val = seq,
predicate: {(box->A!, box->A!): Bool}[A] val = seq)
: USize val ?
Parameters
- value: A!
- offset: USize val = seq
- nth: USize val = seq
- predicate: {(box->A!, box->A!): Bool}[A] val = seq
Returns
- USize val ?
clone [Src]
Clone the array. The new array contains references to the same elements that the old array contains, the elements themselves are not cloned.
fun box clone()
: Array[this->A!] ref^
Returns
- Array[this->A!] ref^
slice [Src]
Create a new array that is a clone of a portion of this array. The range is exclusive and saturated. The new array contains references to the same elements that the old array contains, the elements themselves are not cloned.
fun box slice(
from: USize val = seq,
to: USize val = seq,
step: USize val = seq)
: Array[this->A!] ref^
Parameters
Returns
- Array[this->A!] ref^
permute [Src]
Create a new array with the elements permuted. Permute to an arbitrary order that may include duplicates. An out of bounds index raises an error. The new array contains references to the same elements that the old array contains, the elements themselves are not copied.
fun box permute(
indices: Iterator[USize val] ref)
: Array[this->A!] ref^ ?
Parameters
Returns
- Array[this->A!] ref^ ?
reverse [Src]
Create a new array with the elements in reverse order. The new array contains references to the same elements that the old array contains, the elements themselves are not copied.
fun box reverse()
: Array[this->A!] ref^
Returns
- Array[this->A!] ref^
reverse_in_place [Src]
Reverse the array in place.
fun ref reverse_in_place()
: None val
Returns
- None val
swap_elements [Src]
Swap the element at index i with the element at index j. If either i or j are out of bounds, an error is raised.
fun ref swap_elements(
i: USize val,
j: USize val)
: None val ?
Parameters
Returns
- None val ?
keys [Src]
Return an iterator over the indices in the array.
fun box keys()
: ArrayKeys[A, this->Array[A] ref] ref^
Returns
values [Src]
Return an iterator over the values in the array.
fun box values()
: ArrayValues[A, this->Array[A] ref] ref^
Returns
- ArrayValues[A, this->Array[A] ref] ref^
pairs [Src]
Return an iterator over the (index, value) pairs in the array.
fun box pairs()
: ArrayPairs[A, this->Array[A] ref] ref^
Returns
- ArrayPairs[A, this->Array[A] ref] ref^