-
Notifications
You must be signed in to change notification settings - Fork 0
module std.arrayheap
Jan Špaček edited this page Apr 13, 2016
·
1 revision
This module provides mutable heaps (efficiently stored in an array, hence the name). It also exports a decent sorting algorithm.
-
(arrayheap-new cmp)
creates a new, empty arrayheap, with comparatorcmp
(see module std.map for a description of comparators). -
(arrayheap? heap)
returns true ifheap
is an arrayheap. -
(arrayheap-len heap)
returns the number of elements in arrayheapheap
in O(1). -
(arrayheap-empty? heap)
checks whether the arrayheapheap
is empty. -
(arrayheap-insert! heap key)
inserts thekey
into arrayheapheap
in O(log n) time. -
(arrayheap-minimum heap)
returns the minimum key inheap
in time O(1) or panics if the heap is empty. -
(arrayheap-remove-minimum! heap)
removes and returns the minimum key inheap
or panics if the heap is empty. Time complexity is O(log n). -
(arrayheap-from-array cmp array)
creates a new arrayheap with comparatorcmp
and keys fromarray
. Thearray
is copied, so it can be freely disposed of afterwards. The time needed is O(n). -
(heapsort! cmp array)
ordersarray
in place, comparing the elements withcmp
. Time complexity is O(n log n).