//******************************************** // Hash.cpp // ------------------------------------------- // Non-template functions used in the hash // table implementation // // Author: Leiwen Deng // Date: 11/12/2005 //******************************************** #include "Hash.h" //******************************************** // prime = NextPrime( number ) // ------------------------------------------- // Retrieve the closest prime number no less than //******************************************** int NextPrime( int number ) { if ( number < 9 ) return 11; number |= 1; // Set to the closest odd number int i, i2, ii; while ( 1 ) { bool no_factor = true; // i2 is the square of i, ii is the increment of i2 for ( i = 3, i2 = 9, ii = 16; i2 <= number; i += 2, i2 += ii, ii += 8 ) { if ( number % i == 0 ) { no_factor = false; break; } } if ( no_factor ) return number; number += 2; } }