fn PriorityQueue(comptime T: type, comptime Context: type, comptime compareFn: fn (Context, T, T) Order) type
Priority queue for storing generic data. Initialize with init
. Provide compareFn
that returns Order.lt
when its second argument should get popped before its third argument, Order.eq
if the arguments are of equal priority, or Order.gt
if the third argument should be popped first. For example, to make pop
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 queue before more memory…
Return the number of elements that can be added to the queue before more memory is allocated.
fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void
Ensure that the queue can fit at least
new_capacity
items.fn ensureUnusedCapacity(self: *Self, additional_count: usize) !void
Ensure that the queue can fit at least
additional_count
more item.fn fromOwnedSlice(allocator: Allocator, items: []T, context: Context) Self
PriorityQueue takes ownership of the passed in slice. The slice must have been …
PriorityQueue takes ownership of the passed in slice. The slice must have been allocated with
allocator
. Deinitialize 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 heap 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.
fn removeOrNull(self: *Self) ?T
Pop the highest priority element from the queue. Returns
null
if empty.