std1.0.0-beta-7 SafeC docs

std :: collections::vec

Struct std::Vec

#include <std/collections/vec.h> source

generic<T> struct Vec {
    ?&heap T data;
    unsigned long len;
    unsigned long cap;
}

Fields

§?&heap T datasource

element buffer; null while cap == 0

§unsigned long lensource

element count

§unsigned long capsource

allocated capacity, in elements

Methods

§static struct Vec<T> new()source · definition

empty, no allocation

§static struct Vec<T> with_cap(unsigned long cap)source · definition

empty, room for cap elements

§static struct Vec<T> from_slice([]const T items)source · definition

copies the elements

§int reserve(unsigned long new_cap)source · definition

ensure cap >= new_cap; 0 on OOM

§void shrink()source · definition

cap := len

§unsigned long length() constsource · definition
§unsigned long total_capacity() constsource · definition
§int is_empty() constsource · definition
§?&T get(unsigned long idx) constsource · definition

null if out of range

§&T at(unsigned long idx) constsource · definition

bounds-checked: panics if out of range

§[]T as_slice() constsource · definition

the len elements; valid until the next growth

§int set(unsigned long idx, T value)source · definition

0 if out of range

§?&T front()source · definition
§?&T back()source · definition
§int push(T value)source · definition

0 on OOM

§?T pop()source · definition

null if empty

§int insert(unsigned long idx, T value)source · definition

idx <= len; shifts right

§?T remove(unsigned long idx)source · definition

shifts left; null if out of range

§void clear()source · definition

len := 0, keeps the buffer

§int extend([]const T items)source · definition

append the elements; 0 on OOM

§void reverse()source · definition
§void sort(fn int(const &T, const &T) cmp)source · definition

ascending by cmp (<0, 0, >0); see vec_sort/vec_sort_by for inlined orderings

§long long find(const &T key, fn int(const &T, const &T) cmp) constsource · definition

-1 if absent

§int contains(const &T key, fn int(const &T, const &T) cmp) constsource · definition
§struct Vec<T> clone() constsource · definition

shallow element copy

§void foreach(fn void(&T, unsigned long) func)source · definition
§struct Vec<T> filter(fn int(const &T) pred) constsource · definition
§void drop()source · definition

frees the buffer (Drop)

§void free() consumesource · definition

= drop()