removeIndex
Remove and return element at index. Indices are in the same order as iterator, which is not necessarily priority order.
Function parameters
Parameters
- self:*Self
- index:usize
Priority queue for storing generic data.
Functions
- PriorityQueue
- Priority queue for storing generic data.
Source
Implementation
pub fn removeIndex(self: *Self, index: usize) T {
assert(self.items.len > index);
const last = self.items[self.items.len - 1];
const item = self.items[index];
self.items[index] = last;
self.items.len -= 1;
if (index == self.items.len) {
// Last element removed, nothing more to do.
} else if (index == 0) {
siftDown(self, index);
} else {
const parent_index = ((index - 1) >> 1);
const parent = self.items[parent_index];
if (compareFn(self.context, last, parent) == .gt) {
siftDown(self, index);
} else {
siftUp(self, index);
}
}
return item;
}