Teuchos_HashUtils.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "Teuchos_HashUtils.hpp"
00030 #include "Teuchos_TestForException.hpp"
00031
00032 using namespace Teuchos;
00033
00034
00035 const int HashUtils::primeCount_ = 33;
00036 const int HashUtils::primes_[]
00037 = {11, 19, 37, 59, 101, 163, 271, 443, 733, 1187, 1907, 3061,
00038 4919, 7759, 12379, 19543, 30841, 48487, 75989,
00039 119089, 185971, 290347, 452027, 703657, 1093237,
00040 1695781, 2627993, 4067599, 6290467, 9718019,
00041 15000607, 23133937, 35650091};
00042
00043
00044 int HashUtils::nextPrime(int newCapacity)
00045 {
00046 TEST_FOR_EXCEPTION(newCapacity > primes_[primeCount_-1],
00047 std::logic_error,
00048 "HashUtils::nextPrime() overflow");
00049
00050 for (int i=0; i<primeCount_; i++)
00051 {
00052 if (newCapacity <= primes_[i])
00053 {
00054 return primes_[i];
00055 }
00056 }
00057
00058 TEST_FOR_EXCEPTION(true,
00059 std::logic_error,
00060 "unexpected case in HashUtils::nextPrime()");
00061 return 0;
00062 }