Module: collections.vec
Source: ./collections/vec.reef
Overview
collections/vec - Generic Growable Vector
Collections 0.9.2 / D10. THE growable sequence: Vec absorbs collections.list's insert/remove_at, and list.reef and growable.reef are deleted. Three growable arrays were three sets of bugs to fix.
2x growth, O(1) amortized append.
Usage: import collections.vec import core.option as option let v = vec.create:int v.push(42) let x = v.get(0) // Some(42) -- infers Option[int]
Factories (the per-type ones are gone: create_int_vec, create_int_vec_cap, and their string/bool/float/pointer siblings): createT -> Vec[T], capacity 16 create_with_capacityT -> Vec[T]; n < 1 clamps to 1 (BUG-062)
Methods: push(value) - Append, auto-grows pop(): option.Option[T] - Remove and return last (None if empty) get(index): option.Option[T] - None if out of bounds set(index, value): bool - false if out of bounds insert(index, value): bool - from List; index == len appends remove_at(index): bool - from List; shifts later elements left len(): int capacity(): int - was cap(); every other container spells it capacity() is_empty(): bool clear() - keeps capacity first() / last(): option.Option[T] to_array(): [T] - a copy sized to len, not an out-param
Types
Vec
Fields:
| Name | Type |
|---|---|
items |
[T] |
length |
int |
capacity |
int |
Functions
fn create(): Vec[T]
fn create_with_capacity(cap: int): Vec[T]
cap < 1 clamps to 1 (BUG-062). A zero-capacity vec would leave the backing array zero-length, and the doubling in grow() starts from 0.
Generated by reefc doc