Module: collections.vec
Source: ./collections/vec.reef
Overview
collections/vec - Generic Growable Vector
Provides a type-safe, dynamically-growing array (vector) that automatically resizes when capacity is exceeded. Uses 2x growth factor for O(1) amortized append operations.
Usage: import collections.vec import core.option as option let v = vec.create_int_vec() v.push(42) v.push(100) let x = v.get(0) // Some(42) -- no annotation needed, infers Option[int] let len = v.len() // 2
Available factory functions: create_int_vec() -> Vec[int] create_string_vec() -> Vec[string] create_bool_vec() -> Vec[bool] create_float_vec() -> Vec[float] create_pointer_vec() -> Vec[pointer]
create_int_vec_cap(n) -> Vec[int] with initial capacity n create_string_vec_cap(n) -> Vec[string] with initial capacity n etc.
Methods: push(value) - Append value, auto-grows if needed pop(): option.Option[T] - Remove and return last element (None if empty) get(index): option.Option[T] - Get element at index (None if out of bounds) set(index, value) - Set element at index len(): int - Number of elements cap(): int - Current capacity is_empty(): bool - Check if empty clear() - Remove all elements (keeps capacity) last(): option.Option[T] - Get last element without removing (None if empty) first(): option.Option[T] - Get first element (None if empty)
Types
Vec
Fields:
| Name | Type |
|---|---|
items |
[T] |
length |
int |
capacity |
int |
Functions
fn create_int_vec(): Vec[int]
fn create_int_vec_cap(cap: int): Vec[int]
fn create_string_vec(): Vec[string]
fn create_string_vec_cap(cap: int): Vec[string]
fn create_bool_vec(): Vec[bool]
fn create_bool_vec_cap(cap: int): Vec[bool]
fn create_float_vec(): Vec[float]
fn create_float_vec_cap(cap: int): Vec[float]
fn create_pointer_vec(): Vec[pointer]
fn create_pointer_vec_cap(cap: int): Vec[pointer]
Generated by reefc doc