Haskell Massiv 数组大小限制

huangapple go评论61阅读模式
英文:

Haskell Massiv Array Size Limit

问题

如果Massiv以及其他数组库都使用Int作为索引,那么如何构建和索引超过2^29个元素的数组呢?Int的大小只能达到2^29。我在源代码中注意到,在数组操作中使用了线性索引,所以我认为将一个向量写成二维数组仍然会遇到相同的问题。

在Massiv内部是否有解决方案,或者是否有适用于具有超过2^29个元素的数组的其他数组库?

编辑:@Thomas刚提到Int的maxBound是与机器相关的。然而,我仍然想知道如何索引具有大于Int的maxBound的元素数量的数组。

英文:

If Massiv, as well as other array libraries use Int for indexing, then how does one construct and index arrays larger than 2^29 elements? Int can only be as large as 2^29. I noticed in the source code that Linear indexing is used on array operations aswell so I would assume that just writing a vector as a two dimensional array would still have the same issue.

Is there a solution to this within Massiv or is there another array library suitable for arrays with more than 2^29 elements?

Edit: @Thomas just mentioned that the maxBound of Int is machine dependent. How ever I would still like to know how to index arrays with a number of elements greater than the maxBound of Int.

答案1

得分: 3

没有办法在内存中创建一个包含超过 maxBound :: Int 个元素的列表,因为通常预期 Int 的大小足以覆盖完整的可寻址内存空间。因此,在您的系统上,长度大于 maxBound :: Int 的假设列表或数组将无法适应可寻址内存并无法存储,因此无需一种机制来索引到这样的结构中。

英文:

There is no way to create a list that contains more than maxBound :: Int elements in memory, because the size of an Int is generally expected to be sufficient to cover the full addressable memory space. A hypothetical list or array of length greater than maxBound :: Int on your system therefore would not fit in addressable memory and could not be stored, thus there is no need for a mechanism by which one could index into such a structure.

huangapple
  • 本文由 发表于 2023年1月9日 17:59:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055622.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定