arrays - Data.Array 有多快?

标签 arrays haskell complexity-theory

documentationData.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),因为它必须遍历列表(就像命令式程序一样)。如果您需要大量突变,可以使用 MArrayMVector .

关于arrays - Data.Array 有多快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7289314/

相关文章:

c++ - 为什么 <const char*> 和 <const char[]> 有非常不同的内存或指针行为?

haskell - Haskell 中类型类实例的类型约束?

haskell - Haskell中如何实现多种外部格式的数据多态?

algorithm - 我们是否需要了解/查找/分析算法的每个案例{最佳、平均和最差...所有}场景?

algorithm - 如何找到算法的时间复杂度?

python - 替换 numpy 数组中的子数组的有效方法 - numpy.put 或类似的?

PHP 变量对象属性

javascript - 将数组转换为逗号分隔的文本

haskell - 如何构建返回 Maybe 的镜头 (Haskell)

c# - 设计面向对象和单元测试友好的查询系统