Core Help Root: Objects: Heap


The heap is an efficient implementation of the priority queue. It is currently used by $scheduler and $graph. When you use it only in assignment calls (list = $heap.method(args), in other words), it will operate in the logarithmic time (very fast).

Heap is a list with the property that i-th element of the list has lower priority than either 2*i-th and 2*i+1-st element of the list. Obviously, the first element of the list will have the lowest priority.

$heap.push(heap, element, priority_index)
Add a new element to the heap. In this implementation, heap is assumed to be list of lists, with priority_index determining the priority field of each element.
$heap.del(heap, index, priority_index)
Delete an element at index i of the heap. if index is greater than length of the heap, the method will throw.

Both methods assume that their first argument already is a heap.


the Cold Dark