简体   繁体   English

具有恒定读取时间的并发收集

[英]Concurrent collection with constant read time

ConcurrentDictionary offer constant read time. ConcurrentDictionary提供恒定的读取时间。 I do not need key-value pairs, only keys.. I searched for read times on ConcurrentBag and havent found how it is implemented?我不需要键值对,只需要键..我在ConcurrentBag上搜索了读取时间,但还没有找到它是如何实现的?

Is there a constant read time ConcurrentCollection, besides ConcurrentDictionary?除了 ConcurrentDictionary 之外,是否有恒定的读取时间 ConcurrentCollection?

ConcurrentBag is probably not what you are looking for: ConcurrentBag可能不是您要找的:

Represents a thread-safe, unordered collection of objects.表示一个线程安全的、无序的对象集合。

Which means that it allows duplicates (whereas the dictionary doesn't)这意味着它允许重复(而字典不允许)

Bags are useful for storing objects when ordering doesn't matter, and unlike sets, bags support duplicates.当排序无关紧要时,袋子可用于存储对象,并且与集合不同,袋子支持重复项。

As for performance, it certainly isn't as much performant as a list (so at least O(n) ) ( C# - Performance comparison of ConcurrentBag vs List )至于性能,它的性能肯定不如列表(因此至少为O(n) )( C# - ConcurrentBag 与 List 的性能比较

For a ConcurrentSet check your luck with the custom implementation here: How to implement ConcurrentHashSet in .Net对于ConcurrentSet请在此处检查自定义实现的运气: 如何在 .Net 中实现 ConcurrentHashSet

You can also check the list of Concurrent collections to see if something else suits your needs.您还可以检查并发集合列表以查看是否还有其他内容适合您的需求。

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

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