Std.Vec

import Std.Vec

Source


Types


Vec

type Vec t =
    data: Ptr t
    len: Usz
    cap: Usz

source


Vec.empty

(Vec.empty: fn Unit -> Vec _ is pure) ()

source


Vec.is_empty

(Vec.is_empty: fn (ref (Vec a)) -> Bool is pure) (v: ref (Vec a))

source


Vec.len

(Vec.len: fn (ref (Vec a)) -> Usz is pure) (v: ref (Vec a))

source


Vec.capacity

(Vec.capacity: fn (ref (Vec a)) -> Usz is pure) (v: ref (Vec a))

source


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

source


Vec.extend

Vec.extend (vec: mut Vec t) (s: s) {_: Stream s t e}: Unit can Panic, e

source


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.

source


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.

source


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.

source


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

source


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

source


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.

source


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.

source


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.

source


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.

source


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.

source


Vec.reverse

Vec.reverse (v: mut Vec t): Unit can Fs

Reverse the elements of this vector in place.

source


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.

source


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.

source


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.

source


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.

source


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.

source


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.

source


Vec.sort

Vec.sort (v: mut Vec t) {_: Cmp t}: Unit can Fs

Sort the vector in place using the Cmp ordering.

source


Implicits


Show Implicits
impl print_vec {p: Display t e}: Display (Vec t) e

source


extract_vec

impl extract_vec: Extract (ref Vec t) Usz (ref t) pure

source


stream_vec

implicit stream_vec: Stream (Vec a) a pure

source


stream_imm_vec

implicit stream_imm_vec: Stream (imm Vec a) (imm a) pure

source


drop_vec

impl drop_vec {_: Drop t e}: Drop (Vec t) e

source


eq_vec

impl eq_vec {_: Eq t e}: Eq (Vec t) e

source