Vec[A: Any #share]¶
A persistent vector based on the Hash Array Mapped Trie from 'Ideal Hash Trees' by Phil Bagwell.
Constructors¶
create¶
Returns¶
- Vec[A] val^
Public Functions¶
size¶
Return the amount of values in the vector.
Returns¶
- USize val
apply¶
Get the i-th element, raising an error if the index is out of bounds.
Parameters¶
- i: USize val
Returns¶
- val->A ?
update¶
Return a vector with the i-th element changed, raising an error if the index is out of bounds.
Parameters¶
- i: USize val
- value: val->A
Returns¶
- Vec[A] val ?
insert¶
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.
Parameters¶
- i: USize val
- value: val->A
Returns¶
- Vec[A] val ?
delete¶
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.
Parameters¶
- i: USize val
Returns¶
- Vec[A] val ?
remove¶
Return a vector with n elements removed, beginning at index i.
Parameters¶
Returns¶
- Vec[A] val ?
push¶
Return a vector with the value added to the end.
Parameters¶
- value: val->A
Returns¶
- Vec[A] val
pop¶
Return a vector with the value at the end removed.
Returns¶
- Vec[A] val ?
concat¶
Return a vector with the values of the given iterator added to the end.
Parameters¶
- iter: Iterator[val->A] ref
Returns¶
- Vec[A] val
find¶
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 = 0,
nth: USize val = 0,
predicate: {(A, A): Bool}[A] val = lambda)
: USize val ?
Parameters¶
Returns¶
- USize val ?
contains¶
Returns true if the vector contains value
, false otherwise.
Parameters¶
- value: val->A
- predicate: {(A, A): Bool}[A] val = lambda
Returns¶
- Bool val
slice¶
Return a vector that is a clone of a portion of this vector. The range is exclusive and saturated.
Parameters¶
Returns¶
- Vec[A] val
reverse¶
Return a vector with the elements in reverse order.
Returns¶
- Vec[A] val
keys¶
Return an iterator over the indices in the vector.
Returns¶
- VecKeys[A] ref^
values¶
Return an iterator over the values in the vector.
Returns¶
- VecValues[A] ref^
pairs¶
Return an iterator over the (index, value) pairs in the vector.
Returns¶
- VecPairs[A] ref^