Messing around with a HashTable
I was messing around with collections today and decided to try and work out how the HashTable stores/returns it's items so, I ran the following test:
Dim nums As Integer() = {99, 4, 60, 110, 5}
Dim ht As New Hashtable
For Each num As Integer In nums
ht.Add(num, num)
Next
Label1.Text = ""
For Each key As Object In ht.Keys
Label1.Text &= key.ToString() & " :: " & key.GetHashCode() & Environment.NewLine
Next
I'm not sure exactly what that means with regard to how the enumerator algorithms traverses it's children but, I'm kinda guessing that, under the covers the HashTable uses an algorithm to re-order its children to stop it becoming lopsided which probably resulted in a structure resembling:
110
/ \
5 60
/ \
4 99
While on the subject of structures, I just noticed that Scott Mitchell has a new series starting on them at Msdn : Read Part 1 here.