Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 7th, 2005, 11:49 PM
Registered User
 
Join Date: Aug 2005
Location: , , .
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?

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off




All times are GMT -4. The time now is 01:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.