Functions
fn addOne(self: *Self, allocator: Allocator) Allocator.Error!usize
Extend the list by 1 element, returning the newly reserved index with uninitial…
Extend the list by 1 element, returning the newly reserved index with uninitialized data. Allocates more memory as necesasry.
fn addOneAssumeCapacity(self: *Self) usize
Extend the list by 1 element, asserting
self.capacity
is sufficient to hold a…Extend the list by 1 element, asserting
self.capacity
is sufficient to hold an additional item. Returns the newly reserved index with uninitialized data.fn append(self: *Self, gpa: Allocator, elem: T) !void
Extend the list by 1 element. Allocates more memory as necessary.
fn appendAssumeCapacity(self: *Self, elem: T) void
Extend the list by 1 element, but asserting
self.capacity
is sufficient to ho…Extend the list by 1 element, but asserting
self.capacity
is sufficient to hold an additional item.fn clone(self: Self, gpa: Allocator) !Self
Create a copy of this list with a new backing store, using the specified alloca…
Create a copy of this list with a new backing store, using the specified allocator.
fn ensureTotalCapacity(self: *Self, gpa: Allocator, new_capacity: usize) !void
Modify the array so that it can hold at least
new_capacity
items. Implements …Modify the array so that it can hold at least
new_capacity
items. Implements super-linear growth to achieve amortized O(1) append operations. Invalidates pointers if additional memory is needed.fn ensureUnusedCapacity(self: *Self, gpa: Allocator, additional_count: usize) !void
Modify the array so that it can hold at least
additional_count
more items….Modify the array so that it can hold at least
additional_count
more items. Invalidates pointers if additional memory is needed.fn insert(self: *Self, gpa: Allocator, index: usize, elem: T) !void
Inserts an item into an ordered list. Shifts all elements after and including …
Inserts an item into an ordered list. Shifts all elements after and including the specified index back by one and sets the given index to the specified element. May reallocate and invalidate iterators.
fn insertAssumeCapacity(self: *Self, index: usize, elem: T) void
Inserts an item into an ordered list which has room for it. Shifts all elements…
Inserts an item into an ordered list which has room for it. Shifts all elements after and including the specified index back by one and sets the given index to the specified element. Will not reallocate the array, does not invalidate iterators.
fn items(self: Self, comptime field: Field) []FieldType(field)
Get the slice of values for a specified field. If you need multiple fields, con…
Get the slice of values for a specified field. If you need multiple fields, consider calling slice() instead.
fn orderedRemove(self: *Self, index: usize) void
Remove the specified item from the list, shifting items after it to preserve or…
Remove the specified item from the list, shifting items after it to preserve order.
fn pop(self: *Self) T
Remove and return the last element from the list. Asserts the list has at least…
Remove and return the last element from the list. Asserts the list has at least one item. Invalidates pointers to fields of the removed element.
fn popOrNull(self: *Self) ?T
Remove and return the last element from the list, or return
null
if list is e…Remove and return the last element from the list, or return
null
if list is empty. Invalidates pointers to fields of the removed element, if any.fn resize(self: *Self, gpa: Allocator, new_len: usize) !void
Adjust the list’s length to
new_len
. Does not initialize added items, if any.fn setCapacity(self: *Self, gpa: Allocator, new_capacity: usize) !void
Modify the array so that it can hold exactly
new_capacity
items. Invalidates …Modify the array so that it can hold exactly
new_capacity
items. Invalidates pointers if additional memory is needed.new_capacity
must be greater or equal tolen
.fn shrinkAndFree(self: *Self, gpa: Allocator, new_len: usize) void
Attempt to reduce allocated capacity to
new_len
. Ifnew_len
is greater than…Attempt to reduce allocated capacity to
new_len
. Ifnew_len
is greater than zero, this may fail to reduce the capacity, but the data remains intact and the length is updated to new_len.fn shrinkRetainingCapacity(self: *Self, new_len: usize) void
Reduce length to
new_len
. Invalidates pointers to elementsitems[new_len..]
…Reduce length to
new_len
. Invalidates pointers to elementsitems[new_len..]
. Keeps capacity the same.fn slice(self: Self) Slice
Compute pointers to the start of each field of the array. If you need to access…
Compute pointers to the start of each field of the array. If you need to access multiple fields, calling this may be more efficient than calling
items()
multiple times.fn sort(self: Self, ctx: anytype) void
This function guarantees a stable sort, i.e the relative order of equal elements…
This function guarantees a stable sort, i.e the relative order of equal elements is preserved during sorting. Read more about stable sorting here: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability If this guarantee does not matter,
sortUnstable
might be a faster alternative.ctx
has the following method:fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool
fn sortSpan(self: Self, a: usize, b: usize, ctx: anytype) void
Sorts only the subsection of items between indices
a
andb
(excludingb
) …Sorts only the subsection of items between indices
a
andb
(excludingb
) This function guarantees a stable sort, i.e the relative order of equal elements is preserved during sorting. Read more about stable sorting here: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability If this guarantee does not matter,sortSpanUnstable
might be a faster alternative.ctx
has the following method:fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool
fn sortSpanUnstable(self: Self, a: usize, b: usize, ctx: anytype) void
Sorts only the subsection of items between indices
a
andb
(excludingb
) …Sorts only the subsection of items between indices
a
andb
(excludingb
) This function does NOT guarantee a stable sort, i.e the relative order of equal elements may change during sorting. Due to the weaker guarantees of this function, this may be faster than the stablesortSpan
method. Read more about stable sorting here: https://en.wikipedia.org/wiki/Sorting_algorithm#Stabilityctx
has the following method:fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool
fn sortUnstable(self: Self, ctx: anytype) void
This function does NOT guarantee a stable sort, i.e the relative order of equal …
This function does NOT guarantee a stable sort, i.e the relative order of equal elements may change during sorting. Due to the weaker guarantees of this function, this may be faster than the stable
sort
method. Read more about stable sorting here: https://en.wikipedia.org/wiki/Sorting_algorithm#Stabilityctx
has the following method:fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool
fn swapRemove(self: *Self, index: usize) void
Remove the specified item from the list, swapping the last item in the list int…
Remove the specified item from the list, swapping the last item in the list into its position. Fast, but does not retain list ordering.