[英]Seq for fast random access and fast growth in Scala
What would be the best Scala collection (in 2.8+), mutable or immutable, for the following scenario: 对于以下场景,什么是最好的Scala集合(2.8+),可变或不可变的:
Currently I seem to be getting good performance with the mutable ArrayBuffer, but is there anything better? 目前我似乎在使用可变的ArrayBuffer获得了良好的性能,但有什么更好的吗? Is there an immutable alternative that would do as well? 是否有一个不可改变的替代品也会这样做? Thanks in advance. 提前致谢。
Mutable: ArrayBuffer
Mutable: ArrayBuffer
Immutable: Vector
不变: Vector
If you insert items at random positions more than log(N)/N of the time that you access them, then you should probably use immutable.TreeSet
as all operations are O(log(N)). 如果您在随机位置插入项目超过访问它们的时间的log(N)/ N,那么您应该使用immutable.TreeSet
因为所有操作都是O(log(N))。 If you mostly do accesses or add to the (far) end, ArrayBuffer
and Vector
work well. 如果您主要访问或添加到(远)端, ArrayBuffer
和Vector
工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.