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

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 dequeue.

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

Return the number of elements remaining in the dequeue

fn deinit(self: Self) void

Free memory used by the dequeue.

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

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

Initialize and return a new priority dequeue.

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

Look at the largest element in the dequeue. Returns null if empty.

fn peekMin(self: *Self) ?T

Look at the smallest element in the dequeue. Returns null if empty.

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

Remove and return the largest element from the dequeue.

fn removeMaxOrNull(self: *Self) ?T

Pop the largest element from the dequeue. Returns null if empty.

fn removeMin(self: *Self) T

Remove and return the smallest element from the dequeue.

fn removeMinOrNull(self: *Self) ?T

Pop the smallest element from the dequeue. 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.