What is the lookup time complexity of HashSet(IEqualityComparer)?

后端 未结 5 2078
无人及你
无人及你 2020-12-05 14:39

In C#.NET, I like using HashSets because of their supposed O(1) time complexity for lookups. If I have a large set of data that is going to be queried, I often prefer using

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 15:17

    Lookup is still O(1) if you pass an IEqualityComparer. The hash set still uses the same logic as if you don't pass an IEqualityComparer; it just uses the IEqualityComparer's implementations of GetHashCode and Equals instead of the instance methods of System.Object (or the overrides provided by the object in question).

提交回复
热议问题