-
Notifications
You must be signed in to change notification settings - Fork 0
module std.heap
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 comparatorcmp
. -
(heap-singleton cmp key)
creates a heap with comparatorcmp
and single elementkey
. -
(heap-len h)
returns the number of elements in heaph
in time O(1). -
(heap-empty? h)
tests whether the heaph
is empty. -
(heap-merge h1 h2)
returns a new heap that contains all keys from heaph1
and heaph2
. This functions panics if the comparators of the two heaps are noteqv?
. The time complexity of this operation is O(log n1 + log n2). -
(heap-insert h key)
returns a heap with all keys from heaph
and the keykey
, in O(log n) time. -
(heap-minimum h)
returns the minimal element from heaph
in O(1). -
(heap-remove-minimum h)
returns a new heap with all keys fromh
except the minimal key, in O(log n). -
(heap-to-list h)
returns all keys from heaph
in a sorted list. -
(heap-from-list cmp keys)
creates a new heap with comparatorcmp
and keys from the listkeys
.