简体   繁体   English

Data.Vector会替换Data.Sequence吗?

[英]Does Data.Vector replace Data.Sequence?

I've been quite a fan of Data.Sequence . 我一直很喜欢Data.Sequence But as I've been learning about Data.Vector , it seems that it can do everything Data.Sequence can, but better, plus it can do more stuff. 但是,由于我一直在学习Data.Vector ,它似乎可以做Data.Sequence可以做的一切,但更好,再加上它可以做更多的东西。 Should we be deprecating Data.Sequence and preaching Data.Vector? 我们应该弃用Data.Sequence并讲道Data.Vector吗? Are there any good reasons for using Data.Sequence over Data.Vector? 在Data.Vector上使用Data.Sequence有什么好的理由吗?

None of these data structures can replace the other; 这些数据结构都不能取代另一个; Data.Sequence and Data.Vector are actually at diametrically opposite ends of the data structures available for representing sequences. Data.SequenceData.Vector实际上位于可用于表示序列的数据结构的两端。

  • Data.Vector is a contiguous array of elements. Data.Vector是一个连续的元素数组。 This means small memory footprint and O(1) lookup but terrible mutation, concatenation and copying (O(n) each). 这意味着小内存占用和O(1)查找,但可怕的突变,连接和复制(每个O(n))。 (Mutation can be O(1) if you drop persistence.) (如果你删除持久性,变异可以是O(1)。)
  • Data.Sequence on the other hand is a purely functional tree. 另一方面, Data.Sequence是一个纯粹的功能树。 This means higher memory usage and less locality, but it supports fast access and mutation O(log n) and awesome concatenation O(log(min(n1,n2))) and copying. 这意味着更高的内存使用率和更少的局部性,但它支持快速访问和突变O(log n)和令人敬畏的串联O(log(min(n1,n2)))和复制。

The choice of data structure really depends on the task at hand here. 数据结构的选择实际上取决于此处的任务。

  • Processing large streams of elements in linear fashion or with random lookup is best done with Data.Vector . 以线性方式或随机查找处理大型元素流最好使用Data.Vector
  • If you need to split, concatenate and change your elements a lot, use Data.Sequence . 如果需要拆分,连接和更改元素,请使用Data.Sequence

Sharing a prefix seems like something Seq is better at than Vector . 共享前缀似乎是SeqVector更好的东西。 snoc on Vector is O(n). snocVector为O(n)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM