Question about Hashtable's Bucket

  • Thread starter Thread starter ahoneytrap
  • Start date Start date
A

ahoneytrap

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.
 
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.
 
Back
Top