import Std.Vec
Types
Vec
type Vec t =
data: Ptr t
len: Usz
cap: Usz
Vec.empty
(Vec.empty: fn Unit -> Vec _ is pure) ()
Vec.is_empty
(Vec.is_empty: fn (ref (Vec a)) -> Bool is pure) (v: ref (Vec a))
Vec.len
(Vec.len: fn (ref (Vec a)) -> Usz is pure) (v: ref (Vec a))
Vec.capacity
(Vec.capacity: fn (ref (Vec a)) -> Usz is pure) (v: ref (Vec a))
Vec.of
Vec.of (s: s) {_: Stream s t e}: Vec t can Panic, e
Create a new Vec with the elements from the given stream
Vec.extend
Vec.extend (vec: mut Vec t) (s: s) {_: Stream s t e}: Unit can Panic, e
Vec.reserve
Vec.reserve (v: mut Vec t) (numElems: Usz): Unit can Panic
Reserve space for numElems more elements in v. The new slots are uninitialized.
Vec.push
Vec.push (v: mut Vec t) (elem: t): Unit can Panic
Push an element onto the end of the vector. Resizes if necessary.
Vec.pop
Vec.pop (v: mut Vec t): Maybe t can Fs
Removes the last element of this vector and returns it. Returns None if the vector is empty.
Vec.get
Vec.get (v: imm Vec t) (i: Usz): imm t can Fail
Retrieves the element at the given 0-based index. Fails if the index is out of bounds
Vec.get_unchecked
Vec.get_unchecked (v: imm Vec t) (i: Usz): imm t
An unsafe function to retrieve an element at the given index without checking if the index is inbounds
Vec.remove_index
Vec.remove_index (v: mut Vec t) (idx: Usz): t can Fail
Remove the element at the given index and return it. will Fail if the index is out of bounds.
Vec.remove_first
Vec.remove_first (v: mut Vec t) (elem: t) {_: Eq t e} {_: Copy t}: Maybe Usz can Panic, e
Removes the first instance of the given element from the vector,
returning the index it was found at. Returns None if the element was not found.
Vec.remove_indices
Vec.remove_indices (v: mut Vec t) (idxs: Vec Usz): Unit can Fail
Remove the given indices from the vector Expects the indices to be in sorted order. Will Fail if any index is out of bounds.
Vec.remove_all
Vec.remove_all (v: mut Vec t) (elem: t) {_: Eq t e} {_: Copy t}: Usz can Panic, e
Remove all matching elements from the vector and return the number of elements removed. Uses = to determine element equality.
Vec.swap_last
Vec.swap_last (v: mut Vec t) (idx: Usz): Bool can Fs
Remove an element by swapping it with the last element in O(1) time. Returns true if a swap was performed or false otherwise. Will not swap if the given index is the index of the last element.
Vec.reverse
Vec.reverse (v: mut Vec t): Unit can Fs
Reverse the elements of this vector in place.
Vec.swap
Vec.swap (v: mut Vec t) (i: Usz) (j: Usz): Unit can Fail, Fs
Swap the elements at indices i and j. Fails if either index is out of bounds.
Vec.insert
Vec.insert (v: mut Vec t) (idx: Usz) (elem: t): Unit can Fail, Panic
Insert elem at idx, shifting elements at [idx, len) one position right.
Fails if idx > len.
Vec.dedup
Vec.dedup (v: mut Vec t) {_: Eq t e} {_: Copy t}: Unit can Fs, e
Remove consecutive runs of equal elements, keeping only the first of each run.
Vec.truncate
Vec.truncate (v: mut Vec t) (new_len: Usz) {_: Drop t e}: Unit can e
Shrink the vector to at most new_len elements, dropping any tail.
Does nothing if new_len >= v.len.
Vec.clear
Vec.clear (v: mut Vec t) {_: Drop t e}: Unit can e
Remove and drop every element. After being cleared, a Vec’s length will be zero, but its capacity will be unchanged.
Vec.sort_by
Vec.sort_by (v: mut Vec t) (cmp: fn (ref t) (ref t) [_] -> Bool): Unit
Sort the vector in place using cmp to compare elements.
Insertion sort: stable, O(n^2) worst case. Good enough for small vectors.
Vec.sort
Vec.sort (v: mut Vec t) {_: Cmp t}: Unit can Fs
Sort the vector in place using the Cmp ordering.
Implicits
Show Implicits
print_vec
impl print_vec {p: Display t e}: Display (Vec t) e
extract_vec
impl extract_vec: Extract (ref Vec t) Usz (ref t) pure
stream_vec
implicit stream_vec: Stream (Vec a) a pure
stream_imm_vec
implicit stream_imm_vec: Stream (imm Vec a) (imm a) pure
drop_vec
impl drop_vec {_: Drop t e}: Drop (Vec t) e
eq_vec
impl eq_vec {_: Eq t e}: Eq (Vec t) e