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

GetPrime() public static method

public static GetPrime ( int min ) : int
min int
return int
        public static int GetPrime(int min)
        {
            if (min < 0)
                throw new ArgumentException(SR.Arg_HTCapacityOverflow);
            Contract.EndContractBlock();

            for (int i = 0; i < primes.Length; i++)
            {
                int prime = primes[i];
                if (prime >= min) return prime;
            }

            //outside of our predefined table. 
            //compute the hard way. 
            for (int i = (min | 1); i < Int32.MaxValue; i += 2)
            {
                if (IsPrime(i) && ((i - 1) % Hashtable.HashPrime != 0))
                    return i;
            }
            return min;
        }

Usage Example

Example #1
0
        public Hashtable(int capacity, float loadFactor)
        {
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException("capacity", "NeedNonNegNum");
            }
            if (!(loadFactor >= 0.1f && loadFactor <= 1.0f))
            {
                throw new ArgumentOutOfRangeException("loadFactor", "HashtableLoadFactor");
            }


            this.loadFactor = 0.72f * loadFactor;

            double rawsize = capacity / this.loadFactor;

            if (rawsize > Int32.MaxValue)
            {
                throw new ArgumentException("HTCapacityOverflow");
            }


            int hashsize = (rawsize > InitialSize) ? HashHelpers.GetPrime((int)rawsize) : InitialSize;

            buckets = new bucket[hashsize];

            loadsize           = (int)(this.loadFactor * hashsize);
            isWriterInProgress = false;
        }
All Usage Examples Of System.Collections.HashHelpers::GetPrime