string, GetHashCode, and uniqueness

  • Thread starter Thread starter rh
  • Start date Start date
R

rh

hi all,
msdn says:
"the implementation of GetHashCode provided by the String class
returns unique hash codes for unique string values."
source:
http://msdn.microsoft.com/library/d...ml/frlrfsystemobjectclassgethashcodetopic.asp

sure, hashes must try to yield good distribution but
how could uniqueness be guarranteed in this case?
is it best effort? is it under certain conditions?

GetHashCode returns an int and so it is limited to a 32-bit
number. that's a big number but there are infinite
varieties of strings. just imagine a, aa, aaa, aaaa, aaaaa,
ad infinitum. and that's just using the letter 'a'.

thanks in advance for clarification,
rh
 
rh said:
msdn says:
"the implementation of GetHashCode provided by the String class
returns unique hash codes for unique string values."
source:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre
f/html/frlrfsystemobjectclassgethashcodetopic.asp

It's wrong.

For example, try "blair" and "brainlessness" - two different strings
which return the same hashcode.

Given the context, it *looks* like it's actually trying to say that
different string instances representing the same character data will
give back the same hashcode, but as it stands it's basically incorrect.

I'll email MSDN to let them know.
 
It's wrong.

For example, try "blair" and "brainlessness" - two different strings
which return the same hashcode.


I think that example just proves it has more in built
intelligence than we might expect :-))
 
Back
Top