public int this[int key] {
get {
IntHashtableEntry[] tab = table;
int hash = key;
int index = ( hash & 0x7FFFFFFF ) % tab.Length;
for ( IntHashtableEntry e = tab[index] ; e != null ; e = e.next ) {
if ( e.hash == hash && e.key == key )
return e.value;
}
return 0;
}
set {
// Makes sure the key is not already in the hashtable.
IntHashtableEntry[] tab = table;
int hash = key;
int index = ( hash & 0x7FFFFFFF ) % tab.Length;
for ( IntHashtableEntry e = tab[index] ; e != null ; e = e.next ) {
if ( e.hash == hash && e.key == key ) {
e.value = value;
return;
}
}
if ( count >= threshold ) {
// Rehash the table if the threshold is exceeded.
Rehash();
this[key] = value;
return;
}
// Creates the new entry.
IntHashtableEntry en = new IntHashtableEntry();
en.hash = hash;
en.key = key;
en.value = value;
en.next = tab[index];
tab[index] = en;
++count;
}
}