chickadee » binary-heap » make-binary-heap

make-binary-heap:procedure

where KEY-COMPARE-PROC is a user-supplied function that takes two keys and returns a negative, positive, or zero number depending on how the first key compares to the second.

The returned selector procedure can take one of the following arguments:

'get-max
returns a (key . value) pair for an association in the heap with the largest key. If the heap is empty, an error is signalled.
'delete-max
removes the max key and the corresponding association from the heap. Returns a (key . value) pair of the removed association. If the heap is empty, an error is signalled.
'empty?
returns #t if the heap is empty
'size
returns the size (the number of associations) in the heap
'put
pure variant of PUT!; it returns a new heap object that contains the given association, while the original heap object is unmodified.
'for-each
returns a procedure LAMBDA PROC that will apply the given procedure PROC to each (key . value) association of the heap, from the one with the smallest key all the way to the one with the max key, in an ascending order of keys.
'fold
returns a procedure LAMBDA PROC INITIAL such that, given the associations in the heap ordered by the descending order of keys: (key-n . value-n) ... (key-2 . value-2) (key-1 . value-1) the procedure returns the result of the successive function applications (PROC value-1 (PROC value-2 ... (PROC value-n INITIAL).