Wrox Programmer Forums
|
BOOK: Professional C#, 2nd and 3rd Editions
This is the forum to discuss the Wrox book Professional C#, 3rd Edition by Simon Robinson, Christian Nagel, Karli Watson, Jay Glynn, Morgan Skinner, Bill Evjen; ISBN: 9780764557590
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C#, 2nd and 3rd Editions section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 7th, 2005, 11:49 PM
Registered User
 
Join Date: Aug 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default GetHashCode()

Hello, i'm new here, so let me say hello :)

i'm at page 249, (hashtables) and it lays down the rules of making a GetHashCode() method, which i'm having a hard time understanding.

"It should be fast...."

ok, i guess this means that i should keep the algorithm simple. right?

"It must be consistent..."

i understand that too, if two keys are reffering to the same value, then they should generate the same hash (since the value is indentified by it's hash)

but i don't understand this:

"It should give values that are likely to be distributed across the entire range of numbers that an int can store"

i don't understand what this means. does that mean that the algorithm shouldn't give numbers that are out of bounds? - it doesn't seem so from the explanation:

"The reason for this last condition is because of a potential problem: what happens if you get two entries in the dictionary whose hashes both give the same index"

i have no idea what this means - does it mean that the GetHashCode() has assigned the same number for 2 different indexes?

and if this is the case then what can be done about it? and wouldn't the program crash (since it doesn't know which entry to refer to) rather than just experience a performance hit?










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.