Module collections/array_list
Dynamic array (vector) with amortized O(1) push and O(1) indexed access.
Types
Generic growable array similar to Rust's Vec<T>.
Heap-allocated with automatic resizing and reference-counted cleanup.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), ArrayList(T), ...)
len : (fn(self: Self) -> usize)Returns: usize
capacity : (fn(self: Self) -> usize)Returns: usize
ptr : (fn(self: Self) -> ?*(T))Get a pointer to the underlying data buffer Returns .None if the list is empty or has no allocated buffer
Returns: ?*(T)
as_slice : (fn(self: Self) -> Option(Slice(T)))Get a slice view of the ArrayList Returns a fat pointer Slice(T) with data pointer and length This allows passing ArrayList to functions expecting slices Returns .None for an empty ArrayList with no allocated buffer
Returns: Option(Slice(T))
set_len : (fn(self: Self, new_len: usize) -> unit)Directly set the length of the ArrayList UNSAFE: This does not initialize new elements or free removed elements Only use when you've manually populated the buffer (e.g., via direct memory writes)
Returns: unit
new : (fn() -> Self)Create a new empty ArrayList
Returns: Self
with_capacity : (fn(cap: usize) -> Self)Create an ArrayList with a specific initial cap
Returns: Self
push : (fn(self: Self, value: T) -> Result(unit, ArrayListError))Add an element to the end of the ArrayList
Returns: Result(unit, ArrayListError)
pop : (fn(self: Self) -> Option(T))Remove and return the last element
Returns: Option(T)
get : (fn(self: Self, index: usize) -> Option(T))Get an element by index (bounds checked)
Returns: Option(T)
shrink_to_fit : (fn(self: Self) -> Result(unit, ArrayListError))Shrink the capacity to match the current length This reduces memory usage but may cause reallocation on next push
Returns: Result(unit, ArrayListError)
_free_elements : (fn(self : Self) -> unit)Returns: unit
remove : (fn(self: Self, start: usize, (count : usize) ?= 1) -> Result(usize, ArrayListError))Remove elements from the ArrayList starting at index, removing count elements Returns the number of elements actually removed
Returns: Result(usize, ArrayListError)
slice : (fn(self: Self, start: usize, end: usize) -> Result(Self, ArrayListError))Create a new ArrayList containing a slice of elements from start to end (exclusive) Similar to array slicing in many languages: array[start:end] Returns a new ArrayList with copied elements
Returns: Result(Self, ArrayListError)
ensure_total_capacity : (fn(self: Self, min_cap: usize) -> unit)Ensure the ArrayList can hold at least min_cap total elements
without further reallocation.
Returns: unit
extend_from_ptr : (fn(self: Self, src: *(T), count: usize) -> unit)Append count elements from a raw pointer using memcpy.
The caller must ensure src points to at least count valid elements.
Returns: unit
clear : (fn(self: Self) -> unit)Clear all elements but keep capacity
Returns: unit
fill_with_byte : (fn(self: Self, byte_val: int) -> unit)Fill all elements with a byte pattern using memset. Useful for zeroing bool/integer arrays in O(1). Only safe for types without RC (e.g., bool, u8, usize).
Returns: unit
resize_with_byte : (fn(self: Self, new_len: usize, byte_val: int) -> unit)Resize ArrayList to exactly new_len elements, filling new slots with
a byte pattern via memset. Does not call destructors on removed elements.
Only safe for trivial types (bool, u8, usize, etc.).
Returns: unit
impl(forall(T : Type), ArrayList(T), Index(usize)(...))
Output : TThe output type is the element type T.
index : (fn(self: *(Self), idx: usize) -> *(Self.Output))Returns a pointer to the element at the given index. Panics if the index is out of bounds.
Parameters
| Name | Type | Notes |
|---|---|---|
idx | usize |
Returns: *(Self.Output)
impl(forall(T : Type), ArrayList(T), Dispose(...))
dispose : (fn(self: Self) -> unit)RAII destructor - automatically called when ArrayList goes out of scope
For object, this is called when the reference count drops to zero
Returns: unit
impl(forall(T : Type), ArrayList(T), ...)
into_iter : (fn(self : Self) -> ArrayListIter(T))Returns: ArrayListIter(T)
impl(forall(T : Type), ArrayList(T), ...)
iter : (fn(self : *(Self)) -> ArrayListIterPtr(T))Returns: ArrayListIterPtr(T)
impl(forall(T : Type), where(T <: Eq(T)), ArrayList(T), ...)
contains : (fn(self: Self, value: T) -> bool)Check if the list contains a value
Returns: bool
index_of : (fn(self: Self, value: T) -> Option(usize))Find the first index of a matching value Returns .Some(index) if found, .None otherwise
Returns: Option(usize)
impl(forall(T : Type), ArrayList(T), ...)
reverse : (fn(self: Self) -> unit)Reverse elements in place
Returns: unit
impl(forall(T : Type), where(T <: Ord(T)), ArrayList(T), ...)
sort : (fn(self: Self) -> unit)Sort elements in ascending order using insertion sort
Returns: unit
Error variants for ArrayList operations.
Variants
| Variant | Fields | Description |
|---|---|---|
AllocError | error: AllocError | Memory allocation failed. |
IndexOutOfBounds | index: usize, length: usize | Index is out of bounds for the current length. |
EmptyList | Attempted to access an element from an empty list. |
Value iterator for ArrayList - yields elements by value (T) Used by into_iter() / IntoIterator trait
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), ArrayListIter(T), Iterator(...))
Item : Tnext : (fn(self : *(Self)) -> Option(T))Returns: Option(T)
Pointer iterator for ArrayList - yields pointers to elements (*(T)) Used by iter() method
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), ArrayListIterPtr(T), Iterator(...))
Item : *(T)next : (fn(self : *(Self)) -> Option(*(T)))Returns: Option(*(T))