std.list
std.list: a growable list.
List
pub fn List(comptime T: type) type {
return struct {
buf: []mut T
count: usize
alloc: Allocator
pub fn init(alloc: Allocator) Self
pub fn deinit(self: *mut Self)
pub fn len(self: *Self) usize
pub fn items(self: *Self) []mut T
pub fn append(self: *mut Self, value: T) AllocError!void
pub fn pop(self: *mut Self) ?T
pub fn insert(self: *mut Self, i: usize, value: T) AllocError!void
pub fn orderedRemove(self: *mut Self, i: usize) T
pub fn swapRemove(self: *mut Self, i: usize) T
pub fn clear(self: *mut Self)
}
}
A list of `T` values in one allocation that grows as needed. A slice from `items()` is valid until the next `append` or `insert`.
pub fn init(alloc: Allocator) Self-
An empty list; nothing is allocated until the first `append`.
pub fn deinit(self: *mut Self)-
Frees the memory; the list is empty again.
pub fn len(self: *Self) usize-
The number of elements.
pub fn items(self: *Self) []mut T-
The elements, in order.
pub fn append(self: *mut Self, value: T) AllocError!void-
Adds `value` at the end; the memory doubles when full.
pub fn pop(self: *mut Self) ?T-
Removes and returns the last element; null when empty.
pub fn insert(self: *mut Self, i: usize, value: T) AllocError!void-
Inserts `value` at index `i` (at most `len()`), moving the later elements up.
pub fn orderedRemove(self: *mut Self, i: usize) T-
Removes and returns the element at index `i`, moving the later elements down (keeps the order).
pub fn swapRemove(self: *mut Self, i: usize) T-
Removes and returns the element at index `i`, moving the last element into its place (does not keep the order).
pub fn clear(self: *mut Self)-
Removes every element; keeps the memory.