documentation的 Data.Array
阅读:
Haskell provides indexable arrays, which may be thought of as functions whose domains are isomorphic to contiguous subsets of the integers. Functions restricted in this way can be implemented efficiently; in particular, a programmer may reasonably expect rapid access to the components.
不知道
(!)
能多快和 (//)
是。我可以从这些中期望 O(1) 复杂性,就像我从它们的命令性对应物中一样?
最佳答案
一般来说,是的,您应该能够期望 !
的 O(1)虽然我不确定这是否由标准保证。
如果您想要更快的数组(通过使用流融合),您可能希望查看矢量包。它的设计也更好。
请注意 //
可能是 O(n),因为它必须遍历列表(就像命令式程序一样)。如果您需要大量突变,可以使用 MArray
或 MVector
.
关于arrays - Data.Array 有多快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7289314/