fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
This is a stack data structure where pointers to indexes have the same lifetime as the data structure itself, unlike ArrayList where append() invalidates all existing element pointers. The tradeoff is that elements are not guaranteed to be contiguous. For that, use ArrayList. Note however that most elements are contiguous, making this data structure cache-friendly.
Because it never has to copy elements from an old location to a new location, it does not require its elements to be copyable, and it avoids wasting memory when backed by an ArenaAllocator. Note that the append() and pop() convenience methods perform a copy, but you can instead use addOne(), at(), setCapacity(), and shrinkCapacity() to avoid copying items.
This data structure has O(1) append and O(1) pop.
It supports preallocated elements, making it especially well suited when the expected maximum size is small. prealloc_item_count
must be 0, or a power of 2.
Fields
prealloc_segment: [prealloc_item_count]T = undefined,
dynamic_segments: [][*]T = ref,
len: usize = 0,
Functions
fn append(self: *Self, allocator: Allocator, item: T) Allocator.Error!void
No documentation provided.
fn appendSlice(self: *Self, allocator: Allocator, items: []const T) Allocator.Error!void
No documentation provided.
fn growCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void
Only grows capacity, or retains current capacity.
fn setCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void
Grows or shrinks capacity to match usage. TODO update this and related methods …
Grows or shrinks capacity to match usage. TODO update this and related methods to match the conventions set by ArrayList
fn shrinkCapacity(self: *Self, allocator: Allocator, new_capacity: usize) void
Only shrinks capacity or retains current capacity. It may fail to reduce the ca…
Only shrinks capacity or retains current capacity. It may fail to reduce the capacity in which case the capacity will remain unchanged.
fn shrinkRetainingCapacity(self: *Self, new_len: usize) void
Reduce length to
new_len
. Invalidates pointers for the elements at index new_…Reduce length to
new_len
. Invalidates pointers for the elements at index new_len and beyond.