DoxigAlpha

shrinkAndFree

Reduce allocated capacity to new_len.

Function parameters

Parameters

#
self:*Self
new_len:usize

Priority Dequeue for storing generic data.

Functions

#
PriorityDequeue
Priority Dequeue for storing generic data.

Source

Implementation

#
pub fn shrinkAndFree(self: *Self, new_len: usize) void {
    assert(new_len <= self.items.len);

    // Cannot shrink to smaller than the current queue size without invalidating the heap property
    assert(new_len >= self.len);

    self.items = self.allocator.realloc(self.items[0..], new_len) catch |e| switch (e) {
        error.OutOfMemory => { // no problem, capacity is still correct then.
            self.items.len = new_len;
            return;
        },
    };
}