Doubt about HashCodes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sfreak
    New Member
    • Mar 2010
    • 64

    Doubt about HashCodes

    Hi,

    I have a doubt about c# HashCodes. When I compare a string and get its hashcode an INT will be returned right? We all know that an int has 10 digits lenght. My doubt is about this int generated. I know that a string will always return the SAME hashcode AND the hashcode algorithm says the hashcode is not UNIQUE. So... do we have a chance to get different strings with the same hashcode??? Or there is a criptography behind the String type to generate HashCodes?

    For example

    Code:
    string Name = "Fernando";
    The string Name will generate a hashcode = 1234567890

    if we have another string called LastName which value is "Fernando" the Hashcode generated will be 1234567890 right?

    if I have 9999999999 strings registered in my system or by chance a string which value is "BYTES.COM" can generate a hashcode = 1234567890????

    Hope you can understand the question

    Thanks in advance,

    Fernando Mello
  • pjurri
    New Member
    • Apr 2010
    • 5

    #2
    Hashing is used to search very fast previous stored values.
    A Hashcode (function) is just a translation of a value (string, int, double,...) to a numeric number. You define the maximum hashnumber and the best algorithm is returning an even distributed frequency of hashkeys in the hashspace defined (maximum hashkey). So yes there will be more strings that generate the same hashkey.
    I hope this helps
    Peter

    Comment

    Working...