Let's look at it first.Hashtable.
MSDN: a set of key/value pairs. These key/value pairs are organized according to the hash code of the key.
The Hash algorithm converts any-length input (also called pre- ing and pre-image) into fixed-length output using the Hash algorithm. The output is a Hash value. This type of conversion is a compression ing, that is, the space of hash values is usually much smaller than the input space, and different inputs may be hashed into the same output, instead, it is impossible to uniquely determine the input value from the hash value.
A Hashtable object consists of buckets that contain collection elements. A bucket is a virtual sub-group of each element in Hashtable. Compared with searching and searching in most sets, a bucket can make searching and searching easier. Each bucket is associated with a hash code. The hash code is generated using a hash function and is based on the key of this element.
The default filling factor of the Hashtable class is 1.0, but the default filling factor is 0.72. All the load factors input from the constructor are multiplied by 0.72 in the Hashtable class. This is a demanding number. You may increase or decrease the filling factor by 0.01 at some time. Your Hashtable access efficiency may increase or decrease by 50%, because the filling factor determines the size of the hash table, the size of the hash table affects the probability of Key conflicts, which in turn affects the performance. 0.72 is a balanced value obtained by Microsoft through a large number of experiments.
Let's look at some source code of Hashtable:
Hashtable. ctor Public Hashtable (): this (0, (float) 1f)
{
}
Public Hashtable (int capacity, float loadFactor)
{
If (capacity <0)
{
Throw new ArgumentOutOfRangeException ("capacity", Environment. GetResourceString ("ArgumentOutOfRange_NeedNonNegNum "));
}
If (loadFactor <0.1f) | (loadFactor> 1f ))
{
Throw new ArgumentOutOfRangeException ("loadFactor", Environment. GetResourceString ("ArgumentOutOfRange_HashtableLoadFactor", new object [] {0.1, 1.0 }));
}
This. loadFactor = 0.72f * loadFactor;
Double num = (float) capacity)/this. loadFactor;
If (num> 2147483647.0)
{
Throw new ArgumentException (Environment. GetResourceString ("Arg_HTCapacityOverflow "));
}
Int num2 = (num & gt; 11.0 )? HashHelpers. GetPrime (int) num): 11;
This. buckets = new bucket [num2];
This. loadsize = (