fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compareFn: fn (Context, T, T) Order) type
Priority Dequeue for storing generic data. Initialize with init
. Provide compareFn
that returns Order.lt
when its second argument should get min-popped before its third argument, Order.eq
if the arguments are of equal priority, or Order.gt
if the third argument should be min-popped second. Popping the max element works in reverse. For example, to make popMin
return the smallest number, provide fn lessThan(context: void, a: T, b: T) Order { _ = context; return std.math.order(a, b); }
Functions
fn capacity(self: Self) usize
Return the number of elements that can be added to the dequeue before more memo…
Return the number of elements that can be added to the dequeue before more memory is allocated.
fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void
Ensure that the dequeue can fit at least
new_capacity
items.fn ensureUnusedCapacity(self: *Self, additional_count: usize) !void
Ensure that the dequeue can fit at least
additional_count
more items.fn fromOwnedSlice(allocator: Allocator, items: []T, context: Context) Self
Dequeue takes ownership of the passed in slice. The slice must have been alloca…
Dequeue takes ownership of the passed in slice. The slice must have been allocated with
allocator
. De-initialize withdeinit
.fn iterator(self: *Self) Iterator
Return an iterator that walks the queue without consuming it. Invalidated if th…
Return an iterator that walks the queue without consuming it. Invalidated if the queue is modified.
fn removeIndex(self: *Self, index: usize) T
Remove and return element at index. Indices are in the same order as iterator, …
Remove and return element at index. Indices are in the same order as iterator, which is not necessarily priority order.