Array [Src] [A: A]

Contiguous, resizable memory to store elements of type A.

class ref Array[A: A] is
  Seq[A] ref

Implements


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

Returns


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


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


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


size [Src]

The number of elements in the array.

fun box size()
: USize val

Returns


space [Src]

The available space in the array.

fun box space()
: USize val

Returns


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

Returns


compact [Src]

Try to remove unused space, making it available for garbage collection. The request may be ignored.

fun ref compact()
: None val

Returns


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

Returns


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

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

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

Returns


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

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

Returns


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


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


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


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


clear [Src]

Remove all elements from the array.

fun ref clear()
: None val

Returns


push [Src]

Add an element to the end of the array.

fun ref push(
  value: A)
: None val

Parameters

  • value: A

Returns


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


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

Returns


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


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


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


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


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


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


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


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


reverse_in_place [Src]

Reverse the array in place.

fun ref reverse_in_place()
: None val

Returns


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


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


pairs [Src]

Return an iterator over the (index, value) pairs in the array.

fun box pairs()
: ArrayPairs[A, this->Array[A] ref] ref^

Returns