PSEUDO-CODE FILE: primeAlgs.html
/*
Pseudo-Code for two functions that can be used to find a prime table size
for hashing.
*/
/*
Return TRUE if numberToTest is a prime, else return FALSE.
*/
bool isPrime (int numberToTest)
{
initialize noDivisorFound to TRUE
limit = square root of numberToTest
intialize trialDivisor to 2
while ( noDivisorFound AND (trialDivisor <= limit) )
{
if (numberToTest is evenly divisible by trialDivisor)
set noDivisorFound to FALSE
else add 1 to trialDivisor
}
return noDivisorFound
}
/*
Return the first prime number not less than startVal
(If startVal is prime, this returns startVal.)
*/
int firstPrime(int startVal)
{
initialize candidate to startVal ;
while (candidate is not prime) add 1 to candidate ;
return candidate ;
}