Is there any standard or "most usual" way to represent multidimensional sparse arrays in Haskell (without sacrificing performance too much)?
Something like map< int, map< int, MyClass> > in C++, for example. I've Googled and found just some old academic papers and other people asking for this too.
Thanks!
Data.Map (Int,Int) MyClass
is an excellent suggestion; try that first.
If you run into space problems with that, try IntMap (IntMap MyClass)
. IntMap
s (in module Data.IntMap
) are Map
s with Int
s as keys; being specialised they are more efficient than generic maps. It might or might not make a significant difference.
There is also the Scalable, adaptive persistent container types project which might be of use to you. Those containers (including maps) use significantly less space than normal maps but they are slightly more complicated (although still reasonably easy in use).
How about a Data.Map (Int,Int) MyClass
?
There's HsJudy, which seems to be well-tailored for sparse key sets.
Judy bindings (a C library that implements fast sparse dynamic arrays) for Haskell presenting APIs conforming as much as possible to the existent Haskell library interfaces, like Data.Map and Data.Array.MArray. This binding for the Judy library includes all its four types: mapping from words to bits (Judy1), from words to values (JudyL), from strings to values (JudyHS) and from array-of-bytes to values (JudyHS).
But I'd probably go with a Data.Map.Map (Int, Int) MyClass
until running into scalability or usability issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With