예제 #1
0
        public static int GetPrime(int min)
        {
            if (min < 0)
            {
                throw new ArgumentException();
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            for (int i = 0; i < HashHelpers.primes.Length; i++)
            {
                int prime = HashHelpers.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 (HashHelpers.IsPrime(i) && ((i - 1) % HashHelpers.HashPrime != 0))
                {
                    return(i);
                }
            }

            return(min);
        }
예제 #2
0
 internal static int GetPrime(int min)
 {
     if (min < 0)
     {
         throw new FMException("prime value is zero!");
     }
     for (int i = 0; i < HashHelpers.primes.Length; i++)
     {
         int num = HashHelpers.primes[i];
         if (num >= min)
         {
             return(num);
         }
     }
     for (int j = min | 1; j < 2147483647; j += 2)
     {
         if (HashHelpers.IsPrime(j))
         {
             return(j);
         }
     }
     return(min);
 }