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.

Parameters

T: type,
prealloc_item_count: usize,

Fields

prealloc_segment: [prealloc_item_count]T = undefined,
dynamic_segments: [][*]T = ref,
len: usize = 0,

Functions

fn addOne(self: *Self, allocator: Allocator) Allocator.Error!*T

No documentation provided.

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 at(self: anytype, i: usize) AtType(@TypeOf(self))

No documentation provided.

fn clearAndFree(self: *Self, allocator: Allocator) void

Invalidates all element pointers.

fn clearRetainingCapacity(self: *Self) void

Invalidates all element pointers.

fn constIterator(self: *const Self, start_index: usize) ConstIterator

No documentation provided.

fn count(self: Self) usize

No documentation provided.

fn deinit(self: *Self, allocator: Allocator) void

No documentation provided.

fn growCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void

Only grows capacity, or retains current capacity.

fn iterator(self: *Self, start_index: usize) Iterator

No documentation provided.

fn pop(self: *Self) ?T

No documentation provided.

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 shrink(self: *Self, new_len: usize) void

No documentation provided.

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.

fn uncheckedAt(self: anytype, index: usize) AtType(@TypeOf(self))

No documentation provided.

fn writeToSlice(self: *Self, dest: []T, start: usize) void

No documentation provided.

Values

ConstIterator
undefined
Iterator
undefined
prealloc_count
undefined