ToPrime() публичный статический Метод

public static ToPrime ( int x ) : int
x int
Результат int
Пример #1
0
        void Resize(int size)
        {
            int newSize = HashPrimeNumbers.ToPrime(size);

            // allocate new hash table and link slots array
            var newTable = new int[newSize];
            var newLinks = new Link[newSize];

            for (int i = 0; i < table.Length; i++)
            {
                int current = table[i] - 1;
                while (current != NO_SLOT)
                {
                    int hashCode = newLinks[current].HashCode = GetItemHashCode(slots[current]);
                    int index    = (hashCode & int.MaxValue) % newSize;
                    newLinks[current].Next = newTable[index] - 1;
                    newTable[index]        = current + 1;
                    current = links[current].Next;
                }
            }

            table = newTable;
            links = newLinks;

            // allocate new data slots, copy data
            var newSlots = new T[newSize];

            Array.Copy(slots, 0, newSlots, 0, touched);
            slots = newSlots;

            threshold = (int)(newSize * DEFAULT_LOAD_FACTOR);
        }
Пример #2
0
        private void Resize()
        {
            // From the SDK docs:
            //	 Hashtable is automatically increased
            //	 to the smallest prime number that is larger
            //	 than twice the current number of Hashtable buckets
            int newSize = HashPrimeNumbers.ToPrime((table.Length << 1) | 1);

            // allocate new hash table and link slots array
            int []  newTable     = new int [newSize];
            Link [] newLinkSlots = new Link [newSize];

            for (int i = 0; i < table.Length; i++)
            {
                int cur = table [i] - 1;
                while (cur != NO_SLOT)
                {
                    int hashCode = newLinkSlots [cur].HashCode = hcp.GetHashCode(keySlots [cur]) | HASH_FLAG;
                    int index    = (hashCode & int.MaxValue) % newSize;
                    newLinkSlots [cur].Next = newTable [index] - 1;
                    newTable [index]        = cur + 1;
                    cur = linkSlots [cur].Next;
                }
            }
            table     = newTable;
            linkSlots = newLinkSlots;

            // allocate new data slots, copy data
            TKey []   newKeySlots   = new TKey [newSize];
            TValue [] newValueSlots = new TValue [newSize];
            Array.Copy(keySlots, 0, newKeySlots, 0, touchedSlots);
            Array.Copy(valueSlots, 0, newValueSlots, 0, touchedSlots);
            keySlots   = newKeySlots;
            valueSlots = newValueSlots;

            threshold = (int)(newSize * DEFAULT_LOAD_FACTOR);
        }