SharpDeveloper
System.Collections.Hashtable.Insert
Here is the source code for System.Collections.Hashtable.Insert(Object, Object, Boolean)
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
private void Insert(object key, object nvalue, bool add)
{
uint seed;
uint incr;
if (key == null)
{
throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key"));
}
if (this.count >= this.loadsize)
{
this.expand();
}
else if ((this.occupancy > this.loadsize) && (this.count > 100))
{
this.rehash();
}
uint num3 = this.InitHash(key, this.buckets.Length, out seed, out incr);
int num4 = 0;
int index = -1;
int num6 = (int) (seed % this.buckets.Length);
Label_0071:
if (((index == -1) && (this.buckets[num6].key == this.buckets)) && (this.buckets[num6].hash_coll < 0))
{
index = num6;
}
if ((this.buckets[num6].key == null) || ((this.buckets[num6].key == this.buckets) && ((this.buckets[num6].hash_coll & 0x80000000) == 0)))
{
if (index != -1)
{
num6 = index;
}
Thread.BeginCriticalRegion();
this.isWriterInProgress = true;
this.buckets[num6].val = nvalue;
this.buckets[num6].key = key;
this.buckets[num6].hash_coll |= (int) num3;
this.count++;
this.UpdateVersion();
this.isWriterInProgress = false;
Thread.EndCriticalRegion();
}
else if (((this.buckets[num6].hash_coll & 0x7fffffff) == num3) && this.KeyEquals(this.buckets[num6].key, key))
{
if (add)
{
throw new ArgumentException(Environment.GetResourceString("Argument_AddingDuplicate__", new object[] { this.buckets[num6].key, key }));
}
Thread.BeginCriticalRegion();
this.isWriterInProgress = true;
this.buckets[num6].val = nvalue;
this.UpdateVersion();
this.isWriterInProgress = false;
Thread.EndCriticalRegion();
}
else
{
if ((index == -1) && (this.buckets[num6].hash_coll >= 0))
{
this.buckets[num6].hash_coll |= -2147483648;
this.occupancy++;
}
num6 = (int) ((num6 + incr) % ((ulong) this.buckets.Length));
if (++num4 < this.buckets.Length)
{
goto Label_0071;
}
if (index == -1)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_HashInsertFailed"));
}
Thread.BeginCriticalRegion();
this.isWriterInProgress = true;
this.buckets[index].val = nvalue;
this.buckets[index].key = key;
this.buckets[index].hash_coll |= (int) num3;
this.count++;
this.UpdateVersion();
this.isWriterInProgress = false;
Thread.EndCriticalRegion();
}
}
Related Reading:
Other Interesting Posts
-
Articles
- January 2011
- April 2010
- March 2010
- February 2010
- January 2010
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- February 2009
- December 2008
- November 2008
- October 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
-
Meta







