Hashtables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Trevor Hardwick

    Hashtables

    Hi

    I'm using a hashtable where the key is always an integer. The value stored
    with the key holds another key that gives me a collection. My question is
    will the hashcode generated for the key (an integer) always be unique i.e.
    is there any chance given two different integers that I may get the same
    hashcode?

    If it is possible to get the same hashcode, does the .Net hashtable deal
    with this e.g. when I pass in my unique key will it return me the correct
    value associated with that key.

    Regards


  • Mattias Sjögren

    #2
    Re: Hashtables

    [color=blue]
    >My question is
    >will the hashcode generated for the key (an integer) always be unique i.e.
    >is there any chance given two different integers that I may get the same
    >hashcode?[/color]

    Int32.GetHashCo de just returns itself as the hashcode, so if the int
    values are different, then tha hashcode will be as well.

    [color=blue]
    >If it is possible to get the same hashcode, does the .Net hashtable deal
    >with this e.g. when I pass in my unique key will it return me the correct
    >value associated with that key.[/color]

    Yes.



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    Working...