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); }

Parameters

T: type,
Context: type,
compareFn: fn (Context, T, T) Order,

Fields

items: []T,
len: usize,
allocator: Allocator,
context: Context,

Types

Functions

fn add(self: *Self, elem: T) !void

Insert a new element, maintaining priority.

fn addSlice(self: *Self, items: []const T) !void

Add each element in items to the queue.

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 count(self: Self) usize

Return the number of elements remaining in the priority queue.

fn deinit(self: Self) void

Free memory used by the queue.

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 with deinit.

fn init(allocator: Allocator, context: Context) Self

Initialize and return a priority queue.

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 peek(self: *Self) ?T

Look at the highest priority element in the queue. Returns null if empty.

fn remove(self: *Self) T

Remove and return the highest priority element from the queue.

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.

fn shrinkAndFree(self: *Self, new_len: usize) void

Reduce allocated capacity to new_len.

fn update(self: *Self, elem: T, new_elem: T) !void

No documentation provided.