std::vec
A growable array that owns its elements.
Source: std/vec.volt
Types
struct std::vec
<T: type, Allocator: std::mem::allocator = std::mem::default_allocator> struct vecA growable array that owns its elements. Nothing is allocated until the first push.
| Field | |
|---|---|
ptr: T* = @cast<T*>(@alignof(T)) | a non-null placeholder while cap is 0 |
len: usize = 0 | the elements held |
cap: usize = 0 | room for this many before it grows |
allocator: Allocator = {} | where the memory comes from |
Methods
<T: type, A: std::mem::allocator, B: std::mem::allocator> attach fn eq(this: std::vec<T, A>&, other: std::vec<T, B>&) -> boolvectors: their elements, as slices
<T: type, A: std::mem::allocator> attach fn to_json(this: std::vec<T, A>&) -> std::json::value<T: type, A: std::mem::allocator> attach fn hash(this: std::vec<T, A>&) -> u64<T: type, A: std::mem::allocator> attach fn new_in(static this: std::vec<T>, allocator: A) -> std::vec<T, A>an empty vec that allocates from allocator
<T: type, A: std::mem::allocator> attach fn items(this: std::vec<T, A>&) -> T[..]the elements as a slice (valid until the vec changes)
<T: type, A: std::mem::allocator> attach fn at(this: std::vec<T, A>&, i: usize) -> T&element i, bounds-checked (v[i] is the same place)
<T: type, A: std::mem::allocator> attach operator [](this: std::vec<T, A>&, i: usize) -> T&v[i]: element i, a place (read it, assign to it, borrow it), bounds-checked like at()
<T: type, A: std::mem::allocator> attach fn reserve(this: std::vec<T, A>&, n: usize) -> std::mem::mem_error!voidroom for at least n elements
<T: type, A: std::mem::allocator> attach fn push(this: std::vec<T, A>&, value: T) -> std::mem::mem_error!voidappend value (moved in), growing the memory when it's full
<T: type, A: std::mem::allocator> attach fn pop(this: std::vec<T, A>&) -> T?the last element, moved out
<T: type, A: std::mem::allocator> attach fn first(this: std::vec<T, A>&) -> T*the first element, or null when empty
<T: type, A: std::mem::allocator> attach fn last(this: std::vec<T, A>&) -> T*the last element, or null when empty
<T: type, A: std::mem::allocator> attach fn insert(this: std::vec<T, A>&, i: usize, value: T) -> std::mem::mem_error!voidput value at index i (0..=len), moving the elements from i on up by one
<T: type, A: std::mem::allocator> attach fn remove(this: std::vec<T, A>&, i: usize) -> Ttake element i out, moving the ones after it down by one
<T: type, A: std::mem::allocator> attach fn swap_remove(this: std::vec<T, A>&, i: usize) -> Ttake element i out and put the last element in its place: O(1), but changes the order
<T: type, A: std::mem::allocator> attach fn truncate(this: std::vec<T, A>&, n: usize) -> voiddelete the elements from index n on (nothing when n >= len)
<T: type, A: std::mem::allocator> attach fn resize(this: std::vec<T, A>&, n: usize, value: T) -> std::mem::mem_error!voidn elements: copies of value added at the end, or the ones past n deleted. Filling is one plain loop, which the C compiler turns into a memset for bytes (unchecked: its indices are len..n of a slice of n, and a check per element keeps gcc from making it a memset)
<T: type, A: std::mem::allocator> attach fn extend(this: std::vec<T, A>&, xs: T[..]) -> std::mem::mem_error!voidappend a copy of each element of xs
<T: type, A: std::mem::allocator> attach fn dedup(this: std::vec<T, A>&) -> voiddelete each element equal (by eq) to the one kept before it, so a run of equals keeps its first
<T: type, A: std::mem::allocator, F: type> attach fn retain(this: std::vec<T, A>&, keep: F) -> voiddelete the elements keep(&x) returns false for, keeping the others in order
<T: type, A: std::mem::allocator> attach fn clear(this: std::vec<T, A>&) -> voiddelete every element, keep the memory
<T: type, A: std::mem::allocator> attach fn delete(this: std::vec<T, A>&) -> voiddeletes the elements, then frees the memory
<T: type, A: std::mem::allocator> attach fn copy(this: std::vec<T, A>&) -> std::vec<T, A>a new vec holding a copy of each element, with a copy of the allocator