Skip to content

Vec[A: Any #share]

[Source]

A persistent vector based on the Hash Array Mapped Trie from 'Ideal Hash Trees' by Phil Bagwell.

class val Vec[A: Any #share]

Constructors

create

[Source]

new val create()
: Vec[A] val^

Returns


_create

[Source]

new val _create(
  root': (_VecNode[A] val | None val),
  tail': Array[A] val,
  size': USize val,
  depth': USize val)
: Vec[A] val^

Parameters

Returns


Public Functions

size

[Source]

Return the amount of values in the vector.

fun box size()
: USize val

Returns


apply

[Source]

Get the i-th element, raising an error if the index is out of bounds.

fun box apply(
  i: USize val)
: val->A ?

Parameters

Returns

  • val->A ?

update

[Source]

Return a vector with the i-th element changed, raising an error if the index is out of bounds.

fun val update(
  i: USize val,
  value: val->A)
: Vec[A] val ?

Parameters

  • i: USize val
  • value: val->A

Returns


insert

[Source]

Return a vector with an element inserted. Elements after this are moved up by one index, extending the vector. An out of bounds index raises an error.

fun val insert(
  i: USize val,
  value: val->A)
: Vec[A] val ?

Parameters

  • i: USize val
  • value: val->A

Returns


delete

[Source]

Return a vector with an element deleted. Elements after this are moved down by one index, compacting the vector. An out of bounds index raises an error.

fun val delete(
  i: USize val)
: Vec[A] val ?

Parameters

Returns


remove

[Source]

Return a vector with n elements removed, beginning at index i.

fun val remove(
  i: USize val,
  n: USize val)
: Vec[A] val ?

Parameters

Returns


push

[Source]

Return a vector with the value added to the end.

fun val push(
  value: val->A)
: Vec[A] val

Parameters

  • value: val->A

Returns


pop

[Source]

Return a vector with the value at the end removed.

fun val pop()
: Vec[A] val ?

Returns


concat

[Source]

Return a vector with the values of the given iterator added to the end.

fun val concat(
  iter: Iterator[val->A] ref)
: Vec[A] val

Parameters

Returns


find

[Source]

Find the nth appearance of value from the beginning of the vector, 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 vector, returns the first instance of value found, and uses object identity for comparison.

fun val find(
  value: val->A,
  offset: USize val = seq,
  nth: USize val = seq,
  predicate: {(A, A): Bool}[A] val = seq)
: USize val ?

Parameters

  • value: val->A
  • offset: USize val = seq
  • nth: USize val = seq
  • predicate: {(A, A): Bool}[A] val = seq

Returns


contains

[Source]

Returns true if the vector contains value, false otherwise.

fun val contains(
  value: val->A,
  predicate: {(A, A): Bool}[A] val = seq)
: Bool val

Parameters

  • value: val->A
  • predicate: {(A, A): Bool}[A] val = seq

Returns


slice

[Source]

Return a vector that is a clone of a portion of this vector. The range is exclusive and saturated.

fun val slice(
  from: USize val = seq,
  to: USize val = seq,
  step: USize val = seq)
: Vec[A] val

Parameters

Returns


reverse

[Source]

Return a vector with the elements in reverse order.

fun val reverse()
: Vec[A] val

Returns


keys

[Source]

Return an iterator over the indices in the vector.

fun val keys()
: VecKeys[A] ref^

Returns


values

[Source]

Return an iterator over the values in the vector.

fun val values()
: VecValues[A] ref^

Returns


pairs

[Source]

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

fun val pairs()
: VecPairs[A] ref^

Returns


Private Functions

_tail_offset

[Source]

Return the amount of values in the root.

fun box _tail_offset()
: USize val

Returns


_pow32

[Source]

Raise 32 to the power of n.

fun box _pow32(
  n: USize val)
: USize val

Parameters

Returns


_leaf_nodes

[Source]

fun box _leaf_nodes()
: Array[Array[A] val] ref^

Returns