Haskell中的稀疏数组? [英] Sparse arrays in Haskell?
问题描述
有什么标准或最通常的方式来表示Haskell中的多维稀疏数组(不牺牲性能太多)? int,map< int,MyClass>>在C ++中。我已经Googled,发现只是一些旧的学术论文和其他人也要求这个。
谢谢!
Data.Map(Int,Int)MyClass
是一个很好的建议;尝试一下。
如果遇到空间问题,请尝试 IntMap(IntMap MyClass)
。 IntMap
s(模块 Data.IntMap
)是地图
以 Int
为键;专业化,比通用地图更有效率。它可能或可能不会有显着差异。
还有一个可伸缩的,适应性持久的容器类型可能对您有用的项目。那些容器(包括地图)比普通地图使用的空间明显更少,但它们稍微复杂一点(尽管使用起来还是比较容易)。
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).
这篇关于Haskell中的稀疏数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!