OCaml batteries contain a polymorphic priority queue in a module called BatHeap . You can use it by simply adding items to an empty heap, etc.
Jane Stree Core has a priority priority queue in a module named Heap .
Update:
A bunch of Jane Stree Nuclei is really a fantasy. One way to describe this is through two heap interfaces. The first interface is a set of ordered values, whose smallest element can be located in constant time and deleted during the log. The second interface considers the heap as a collection of containers ("heaps of elements") with ordered values ββin them. If you are ready to handle these containers explicitly, some of the heap operations can be completed faster.
Here is a very simple example that uses a bunch (first interface) to sort the list:
let heapsort l = let heap = Core.Std.Heap.create compare in List.iter (fun x -> ignore (Core.Std.Heap.push heap x)) l; let rec extract () = match Core.Std.Heap.pop heap with | None -> [] | Some x -> x :: extract () in extract ()
(This code is somewhat artificial, it just shows how to put the values ββin a heap and return them.)
Here is an example of running this code (in OCaml toplevel with Core support):
#
source share