Previous: , Up: binary heaps   [Index]


39.6 Miscellaneous operations on heaps

The following bindings are exported by the library (vicare containers binary-heaps). The bindings whose name is prefixed with $ are unsafe operations: they do not validate their arguments before accessing them.

Function: binary-heap-copy heap
Function: $binary-heap-copy heap

Build and return a new instance of <binary-heap> using the same comparison predicate of heap and containing the same objects of heap.

Function: binary-heap-fold! kons knil heap
Function: $binary-heap-fold! kons knil heap

While the heap is not empty: apply kons to knil and the next top object; the return value of the application becomes the new knil; return the return value of the last application. After a call to this function: the heap is left empty.

(binary-heap-fold!
    (lambda (knil obj)
      (cons obj knil))
  '()
  (fold-left (lambda (heap obj)
               (binary-heap-push! heap obj)
               heap)
    (make-binary-heap <)
    '(2 4 0 1 3)))
⇒ (4 3 2 1 0)
Function: binary-heap-merge heap1 heap2
Function: $binary-heap-merge heap1 heap2

Build and return a new instance of <binary-heap> using the same comparison predicate of heap1 and containing the same objects of both heap1 and heap2. The arguments heap1 and heap2 are left unchanged.

Function: binary-heap-blend! heap1 heap2
Function: $binary-heap-blend! heap1 heap2

Destructively extract all the objects from heap2 and add them to heap1. Return heap1 itself.