System.Collections.HashHelpers.ExpandPrime C# (CSharp) Method

ExpandPrime() public static method

public static ExpandPrime ( int oldSize ) : int
oldSize int
return int
        public static int ExpandPrime(int oldSize)
        {
            int newSize = 2 * oldSize;

            // Allow the hashtables to grow to maximum possible size (~2G elements) before encountering capacity overflow.
            // Note that this check works even when _items.Length overflowed thanks to the (uint) cast
            if ((uint)newSize > MaxPrimeArrayLength && MaxPrimeArrayLength > oldSize)
            {
                Debug.Assert(MaxPrimeArrayLength == GetPrime(MaxPrimeArrayLength), "Invalid MaxPrimeArrayLength");
                return MaxPrimeArrayLength;
            }

            return GetPrime(newSize);
        }

Usage Example

Example #1
0
        private void expand()
        {
            int rawsize = HashHelpers.ExpandPrime(buckets.Length);

            rehash(rawsize, false);
        }