Dictionary,HashSet的访问时间 [英] Access times for Dictionary, HashSet

查看:121
本文介绍了Dictionary,HashSet的访问时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 查找字典中的值

  2. 检查是否HashSet有一个值

它是O(1)像C ++ 0x的unordered_map吗?

$ b $是的,当您使用Contains方法或Dictionary的索引器时。



从文档:


字典(TKey,TValue)通用类提供从一组键到一组值的映射。字典中的每个添加都包含一个值及其关联的键。通过使用其键来获取值非常快,接近于O(1),因为Dictionary(Of TKey,TValue)类被实现为哈希表。


http://msdn.microsoft.com/en -us / library / xfhwa508.aspx


What are the access times for:

  1. Looking up a value in Dictionary
  2. Check whether a HashSet has a value

Is it O(1) like unordered_map of C++0x?

解决方案

Yes, when you use the Contains method or the indexer of the Dictionary.

From the docs:

The Dictionary(Of TKey, TValue) generic class provides a mapping from a set of keys to a set of values. Each addition to the dictionary consists of a value and its associated key. Retrieving a value by using its key is very fast, close to O(1), because the Dictionary(Of TKey, TValue) class is implemented as a hash table.

http://msdn.microsoft.com/en-us/library/xfhwa508.aspx

这篇关于Dictionary,HashSet的访问时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆