System.Collections.Generic.HashPrimeNumbers.ToPrime C# (CSharp) Method

ToPrime() public static method

public static ToPrime ( int x ) : int
x int
return int
        public static int ToPrime(int x)
        {
            for (int i = 0; i < primeTbl.Length; i++)
            {
                if (x <= primeTbl[i])
                    return primeTbl[i];
            }
            return CalcPrime(x);
        }

Usage Example

Example #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);
        }
All Usage Examples Of System.Collections.Generic.HashPrimeNumbers::ToPrime