Data.Array有多快? [英] How fast is Data.Array?

查看:59
本文介绍了Data.Array有多快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<$ c $的文档 c> Data.Array 读取:

The documentation of Data.Array reads:


Haskell提供了可索引数组,可以将其视为
函数的域与
整数的连续子集同构。以这种方式限制的功能可以有效地实现
;特别是程序员可能会合理地期望
能够快速访问组件。

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.

我想知道<$ c $有多快c>(!)和(//) be。我可以像从命令命令中那样期望O(1)的复杂性吗?

I wonder how fast can (!) and (//) be. Can I expect O(1) complexity from these, as I would have from their imperative counterparts?

推荐答案

通常,是的,您应该可以从中获得O(1)!,尽管我不确定标准是否可以保证。

In general, yes, you should be able to expect O(1) from ! although I'm not sure if thats guaranteed by the standard.

但是,如果您想要更快的数组(通过使用流融合),则可能需要查看矢量包。

You might want to see the vector package if you want faster arrays though (through use of stream fusion). It is also better designed.

请注意,尽管 // 可能是O(n),因为它必须遍历列表(就像命令式程序一样)。如果需要大量突变,可以使用 MArray MVector

Note that // is probably O(n) though because it has to traverse the list (just like an imperative program would). If you need a lot of mutation you can use MArray orMVector.

这篇关于Data.Array有多快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆