public virtual void Remove(Object key)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
}
Contract.EndContractBlock();
Debug.Assert(!_isWriterInProgress, "Race condition detected in usages of Hashtable - multiple threads appear to be writing to a Hashtable instance simultaneously! Don't do that - use Hashtable.Synchronized.");
uint seed;
uint incr;
// Assuming only one concurrent writer, write directly into buckets.
uint hashcode = InitHash(key, _buckets.Length, out seed, out incr);
int ntry = 0;
bucket b;
int bn = (int)(seed % (uint)_buckets.Length); // bucketNumber
do
{
b = _buckets[bn];
if (((b.hash_coll & 0x7FFFFFFF) == hashcode) &&
KeyEquals(b.key, key))
{
_isWriterInProgress = true;
// Clear hash_coll field, then key, then value
_buckets[bn].hash_coll &= unchecked((int)0x80000000);
if (_buckets[bn].hash_coll != 0)
{
_buckets[bn].key = _buckets;
}
else
{
_buckets[bn].key = null;
}
_buckets[bn].val = null; // Free object references sooner & simplify ContainsValue.
_count--;
UpdateVersion();
_isWriterInProgress = false;
return;
}
bn = (int)(((long)bn + incr) % (uint)_buckets.Length);
} while (b.hash_coll < 0 && ++ntry < _buckets.Length);
}