简体   繁体   English

Scala列表性能

[英]Scala List performance

Does anyone know of a source for performance characteristics on the "contains" method within the different flavors of Scala Lists? 有谁知道Scala列表不同风格中“包含”方法的性能特征来源? The scala language docs cover the primary operations like head, tail, append, and so forth, but don't seem to cover the performance of 'contains.' Scala语言文档涵盖了诸如head,tail,append等的主要操作,但似乎并未涵盖“ contains”的性能。 (Or at least I didn't find anything as such.) (或者至少我没有找到任何类似的东西。)

FWIW, I need the fastest structure that will effectively tell me whether an element exists within its listing. FWIW,我需要最快的结构来有效地告诉我列表中是否存在某个元素。 That listing, once initially compiled, will not undergo any further a/m/d operations. 该清单经过初步编译后,将不再进行进一步的a / m / d操作。

This is for Scala version 2.10.0 这是针对Scala 2.10.0版本的

EDIT: in case it should make any difference, this is a listing of text segments (~16 to 48 characters each.) And, to clarify, the docs did contain one small table that showed look-up performance - but for only a small set of the list/map implementations. 编辑:如果应该有所不同,这是文本段的列表(每个文本段约16到48个字符。)并且为了澄清起见,文档确实包含一个显示查询性能的小表-但是仅一小部分列表/地图实现的集合。

This seems the right job for a tree, a RB tree in this case, where the search executed by contains performs logarithmically in the number of fragments. 对于一棵树(在这种情况下为RB树)来说,这似乎是正确的工作,其中由contains执行的搜索对数为碎片数。

Since you only need to check containment, you should use a set to further reduce lookup time. 由于只需要检查遏制,您应该使用一个集合来进一步减少查找时间。

The solution is TreeSet 解决方案是TreeSet

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

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