Skip to content
Jan Špaček edited this page Apr 12, 2016 · 1 revision

This module provides persistent heaps. Heaps allow fast access to the minimal element, as determined by the comparator (see module std.map for description of comparators).

  • (heap-new cmp) creates an empty heap with comparator cmp.
  • (heap-singleton cmp key) creates a heap with comparator cmp and single element key.
  • (heap-len h) returns the number of elements in heap h in time O(1).
  • (heap-empty? h) tests whether the heap h is empty.
  • (heap-merge h1 h2) returns a new heap that contains all keys from heap h1 and heap h2. This functions panics if the comparators of the two heaps are not eqv?. The time complexity of this operation is O(log n1 + log n2).
  • (heap-insert h key) returns a heap with all keys from heap h and the key key, in O(log n) time.
  • (heap-minimum h) returns the minimal element from heap h in O(1).
  • (heap-remove-minimum h) returns a new heap with all keys from h except the minimal key, in O(log n).
  • (heap-to-list h) returns all keys from heap h in a sorted list.
  • (heap-from-list cmp keys) creates a new heap with comparator cmp and keys from the list keys.