Method code for $heap.del()

[Turn on line numbering]
arg heap, i, priority_ind;
var j, len, min;

len = listlen(heap);
if (i > len)
    throw(~invarg, "Index %d out of bounds - can't delete".format(i));
anticipate_assignment();
while (i != len) {
    min = len;
    j = i * 2;
    if (j < len && heap[j][priority_ind] < heap[min][priority_ind])
        min = j;
    j++;
    if (j < len && heap[j][priority_ind] < heap[min][priority_ind])
        min = j;
    heap = replace(heap, i, heap[min]);
    i = min;
}
heap = heap.subrange(1, len - 1);
return heap;

// Miroslav Silovic
// Created 24-Nov-1996 as a part of ColdCore, see: @help Credit

Tlon