Data.List的循环是否有矢量替代?
Data.Vector文档有一个标题为回收支持的部分听起来像我想要的但是new功能和clone显然没有做什么cycle 。
我正在考虑的解决方案是重复索引向量(计数器mod为向量的长度)。
我需要做的一个例子是,我需要一个随机洗牌网格的无限列表,但网格很大,因此将数百万个网格保存在内存中并不理想。 我意识到,随机循环是否相对较小并不重要,因此我只生成了一个只有几百个网格的列表,然后使用Data.List.cycle来给出无限长度的错觉。 我现在将网格list转换为网格Vector ,不能再使用cycle 。
Is there a vector alternative of Data.List's cycle?
The Data.Vector docs have a section titled Recycling support that sounds like it is what I would want but the functions new and clone clearly don't do what cycle does.
The solution I was thinking about is just repeatedly index the vector with (a counter mod the length of the vector).
An example of what I needed to do, is I need an infinite list of randomly shuffled grids, but the grids are large and so keeping millions of them in memory is not ideal. I realized that it did not matter if the cycle of random was relatively small, so instead I generated a list of only a couple hundred grids and then used Data.List.cycle to give the illusion of infinite length. I am now converted the list of grids to a Vector of grids and can no longer use cycle.
最满意答案
不Vector.cycle包中现有的Vector至少分配了脊椎,因此你不能拥有没有无限内存的Vector.cycle 。
例如, Data.Vector使用Data.Primitive.Array 。
由于矢量包的内部(例如Data.Vector.Generic.* )允许您以灵活的方式定义其他类型的矢量,因此您可以创建一个矢量类型来计算索引的长度,以提供循环行为(并包括与drop一起使用的偏移量)。 所以施工是可以想象的,只是没有完成。
No. The existing Vector's in the Vector package allocate at least the spine and thus you can not have Vector.cycle without infinite memory.
For example, Data.Vector uses Data.Primitive.Array.
Since the internals of the vector package (e.g. Data.Vector.Generic.*) allow you to define other types of Vectors in a flexible manner, you could make a vector type that computes the index modulo the length to provide cyclic behavior (and includes an offset for use with drop). So the construction is conceivable, just not done.
更多推荐
发布评论