Question about Hashtable's Bucket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ahoneytrap@googlemail.com

    Question about Hashtable's Bucket

    Hello all,

    I've been scouring through the source code (reflector, shared source)
    of the framework and was looking at the hashtable implementation.

    From what I can tell, the default implentation uses an array of Bucket
    objects which contain the key and value. Then the hash is calculated
    elsewhere to point to the index in the array of buckets.

    So hashTable.Add(" tree","value") would create a bucket object with
    "tree" and "value" which is added to the array (which is resized every
    100 entries from what I can see). What I'm wondering is how does it
    know where in the array to place the item? I appreciate some kind of
    modula is done based on the int hash of "tree", but can anyone be more
    precise? I'm interested in how it places it in the array rather than
    the hash function itself.

  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: Question about Hashtable's Bucket

    ahoneytrap@goog lemail.com wrote:
    Hello all,
    >
    I've been scouring through the source code (reflector, shared source)
    of the framework and was looking at the hashtable implementation.
    >
    From what I can tell, the default implentation uses an array of Bucket
    objects which contain the key and value. Then the hash is calculated
    elsewhere to point to the index in the array of buckets.
    >
    So hashTable.Add(" tree","value") would create a bucket object with
    "tree" and "value" which is added to the array (which is resized every
    100 entries from what I can see). What I'm wondering is how does it
    know where in the array to place the item? I appreciate some kind of
    modula is done based on the int hash of "tree", but can anyone be more
    precise? I'm interested in how it places it in the array rather than
    the hash function itself.
    >
    It takes the hashcode modulo the size of the array, so if the size is 5
    and the hash code is 8, the index would be (8 % 5) = 3.

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    Working...