Does the F# library include a priority queue? Else can someone point to me an implementation of priority queue in F#?
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.