예제 #1
0
        private void Resize()
        {
            int num = HashPrimeNumbers.ToPrime(this.table.Length << 1 | 1);

            int[]  array  = new int[num];
            Link[] array2 = new Link[num];
            for (int i = 0; i < this.table.Length; i++)
            {
                for (int num2 = this.table[i] - 1; num2 != -1; num2 = this.linkSlots[num2].Next)
                {
                    int num3 = array2[num2].HashCode = (this.hcp.GetHashCode(this.keySlots[num2]) | int.MinValue);
                    int num4 = (num3 & int.MaxValue) % num;
                    array2[num2].Next = array[num4] - 1;
                    array[num4]       = num2 + 1;
                }
            }
            this.table     = array;
            this.linkSlots = array2;
            TKey[]   destinationArray  = new TKey[num];
            TValue[] destinationArray2 = new TValue[num];
            Array.Copy(this.keySlots, 0, destinationArray, 0, this.touchedSlots);
            Array.Copy(this.valueSlots, 0, destinationArray2, 0, this.touchedSlots);
            this.keySlots   = destinationArray;
            this.valueSlots = destinationArray2;
            this.threshold  = (int)((float)num * 0.9f);
        }
예제 #2
0
        private void Resize()
        {
            int prime = HashPrimeNumbers.ToPrime((int)this.table.Length << 1 | 1);

            int[]      numArray  = new int[prime];
            bgs.Link[] linkArray = new bgs.Link[prime];
            for (int i = 0; i < (int)this.table.Length; i++)
            {
                for (int j = this.table[i] - 1; j != -1; j = this.linkSlots[j].Next)
                {
                    int hashCode = this.hcp.GetHashCode(this.keySlots[j]) | -2147483648;
                    int num      = hashCode;
                    linkArray[j].HashCode = hashCode;
                    int num1 = (num & 2147483647) % prime;
                    linkArray[j].Next = numArray[num1] - 1;
                    numArray[num1]    = j + 1;
                }
            }
            this.table     = numArray;
            this.linkSlots = linkArray;
            TKey[]   tKeyArray   = new TKey[prime];
            TValue[] tValueArray = new TValue[prime];
            Array.Copy(this.keySlots, 0, tKeyArray, 0, this.touchedSlots);
            Array.Copy(this.valueSlots, 0, tValueArray, 0, this.touchedSlots);
            this.keySlots   = tKeyArray;
            this.valueSlots = tValueArray;
            this.threshold  = (int)((float)prime * 0.9f);
        }
예제 #3
0
 public static int ToPrime(int x)
 {
     for (int i = 0; i < (int)HashPrimeNumbers.primeTbl.Length; i++)
     {
         if (x <= HashPrimeNumbers.primeTbl[i])
         {
             return(HashPrimeNumbers.primeTbl[i]);
         }
     }
     return(HashPrimeNumbers.CalcPrime(x));
 }
예제 #4
0
 public static int CalcPrime(int x)
 {
     for (int i = (x & -2) - 1; i < 2147483647; i += 2)
     {
         if (HashPrimeNumbers.TestPrime(i))
         {
             return(i);
         }
     }
     return(x);
 }