开发者

Good resource for explaining how hash codes are used in collections

Can anyone give a good explanation and / or links to a goo开发者_如何学运维d resource of how hash codes are used in storing and retrieving objects in hashtables, dictionaries etc, specifically in C# / .NET.

I'm interested to see how Equals and GetHashCode are used collectively when storing and retrieving items.


It depends on the collection, but for a dictionary the hash code is used to determine which bucket the object is added to, and Equals is used to find the item within the bucket, amongst other items which may have the same hash.


This is a pretty good demo: http://research.cs.vt.edu/AVresearch/hashing/buckethash.php


try object.GetHashCode.

"A hash code is a numeric value that is used to identify an object during equality testing. It can also serve as an index for an object in a collection. The GetHashCode method is suitable for use in hashing algorithms and data structures such as a hash table."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜