Does the F# library include a priority queue? Else can someone point to me an implementation of priority queue in F#?
With F# you can use any .NET library so if you are ok with using an implementation which is not written in F# I Wintellect Power Collection Library.
Take a look at http://lepensemoi.free.fr/index.php/tag/data-structure for a whole bunch of F# implementations of various data structures.
Just use an F# Set
of pairs of your element type with a unique int (to allow duplicates) and extract your elements with set.MinElement
or set.MaxElement
. All of the relevant operations are O(log n) time complexity. If you really need O(1) repeated access to the minimum element you can simply cache it and update the cache upon insertion if a new minimum element is found.
There are many kinds of heap data structures that you could try (skew heaps, splay heaps, pairing heaps, binomial heaps, skew binomial heaps, bootstrapped variants of the above). For a detailed analysis of their design, implementation and real-world performance see the article Data structures: heaps in The F#.NET Journal.
There is a discussion of functional data structures for priority queues in issue 16 of The Monad.Reader, which is interesting.
It includes a description of pairing heaps which are fast and very easy to implement.