I want to make my heap data structure. Also i want to make operations with it in STM monad in multi-threaded application. The heap have size of 10 millions of elements. There are many operations on heap.
I have looked on this packages
As i mean both of them are persistent. If we modify this data structure we get two versions.
It is memory ineffective for heap with big size.
As i guess i need to implement mutable heap.
I want to hear your opinion and advice to get what i want.
Thanks.
As Ankur points out, you may be outside the bounds of the pure functional side of Haskell. At least I have never seen a pure extract-min data structure with good memory performance — don’t take that to mean there isn’t one. Have you profiled the existing libraries to make sure that they are not adequate for your needs? (Remember that a persistent data structure does not mean that the entire data structure is copied whenever a mutation is made, there can be lots of sharing between different “versions”).
However, Haskell also has an imperative side, and you could implement a heap on that side. The performance characteristics of imperative Haskell are close to those of any other imperative language, so you will probably want to base your heap off of a mutable array of some type.
It might be tricky to implement it in a way that works nicely with STM, whose core concept is the TVar. You could base it off of a (even non-mutable) array of TVars, but since every operation touches the root of the heap there will be lots of contention and the STM overhead will hurt you. I would be more inclined to serialize access to the heap to one thread at a time using locks / MVars.
I know Data.Vector.Mutable is a popular mutable array library. Others will be more informed than I in recommending a good mutable array library for your purposes.