Access times for Dictionary, HashSet

后端 未结 1 1120
一个人的身影
一个人的身影 2021-01-21 11:08

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++0

相关标签:
1条回答
  • 2021-01-21 11:41

    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

    0 讨论(0)
提交回复
热议问题