There seem to be several priority queue implementations available off-the-shelf for Haskell. For instance, there's:
- Data.PriorityQueue.FingerTree (in fingertree-0.0.1.0 on hackage)
- Data.PurePriorityQueue (in pure-priority-queue-0.14 on hackage)
both of which appear to be pure priority queue data structures. The former is based on finger trees, a data structure with which I'm unfamiliar; the latter is a wrapper around Data.Map. There's also
- Data.Heap (in heap-1.0.0 on hackage)
which defines purely functional heap data structures from which one can trivially make priority queues. . There're also
- Data.Heap (in heaps-0.2 on hackage)
- Data.MeldableHeap (in meldable-heap-2.0.3 on hackage)
which both implement purely functional meldable heaps using the Brodal/Okasaki data structure, which I believe is analogous to the binomial heap data structure in non-pure functional land.
(Oh, and there's also
- Data.PriorityQueue (in priority-queue-0.2.2 on hackage)
whose function is unclear to me, but which seems to be related building priority queues attached to a monad, and which seems to be built on top of Data.Map anyhow. In this question, I'm concerned with purely functional priority queues, so I think the priority-queue-0.2.2 package is irrelevant. But correct me if I'm wrong!)
I need a pure functional priority queue data structure for a project I'm building. I was wondering if anyone could provide any words of wisdom as I decide between the embarrassment of riches provided by hackage. Specifically:
- Suppose I want do features apart from the traditional priority queue insert and extract-min operations, in a purely-functional/immutable presentation. What are the pros and cons of the packages mentioned above? Does anyone have experience using any of them 'in anger'? What are the tradeoffs in performance? Reliability? Which are used more widely by others? (Using those might make my code easier for others to read, since they will be more likely to be familiar with the library.) Are there any other things I should know before making a decision between them?
- If I also want efficient merging of priority queues, what then? (I don't for this project, but I thought adding this but would make the SO question more useful for future readers.)
- Are there any other priority queue packages out there that I missed out?
priority-queue-0.2.2
- it was one of my very early endeavors in Haskell and while i've never actually found or been notified of any problems with that version, it's almost certainly not as well-thought-out as the others. Its purpose is indeed for use mostly with IORef, STRef, et al. It could be used in State/StateT for a "pure" interface, but is really not worth the trouble of doing so when there are so many other options out there (including just plain "Map", which has 'minView' and 'maxView' functions). – mokus