|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Functions | |
| size_t | next_prime (unsigned long n) |
| Find the smallest prime number >= n from the database. | |
| bool | check_primes_database () |
| Verify the integrity of the prime database. | |
| bool | is_prime (unsigned long n) |
| Test if a number is prime using trial division. | |
| unsigned long | next_prime_number_greater_than (unsigned long n) |
| Find the next prime strictly greater than n. | |
Variables | |
| const unsigned long | primeList [] |
| Pre-computed array of prime numbers for fast lookup. | |
| const size_t | numPrimes = sizeof(primeList) / sizeof(primeList[0]) |
| Number of primes in the pre-computed database. | |
| const unsigned long | DefaultPrime = primeList[0] |
| Default prime number used when no specific size is requested. | |
| bool Primes::check_primes_database | ( | ) |
|
inline |
Test if a number is prime using trial division.
Checks divisibility by all integers from 2 to sqrt(n).
| n | Number to test for primality |
Definition at line 128 of file primes.H.
References sqrt().
Referenced by next_prime(), next_prime_number_greater_than(), TEST(), TEST(), and TEST().
| unsigned long Primes::next_prime | ( | unsigned long | n | ) |
Find the smallest prime number >= n from the database.
Performs binary search on the pre-computed prime database to find a suitable prime for hash table sizing.
| n | Minimum value for the prime |
Definition at line 383 of file primes.C.
References is_prime(), next_prime_number_greater_than(), and primeList.
Referenced by OhashCommon< HashTbl, Key >::check_resize_before_insert(), Aleph::GenLhashTable< Key, BucketType, Cmp >::insert(), Aleph::GenLhashTable< Key, BucketType, Cmp >::remove(), OhashCommon< HashTbl, Key >::remove_ptr(), Aleph::GenLhashTable< Key, BucketType, Cmp >::search_or_insert(), and TEST().
|
inline |
Find the next prime strictly greater than n.
Unlike next_prime() which uses a database, this function computes primes dynamically using trial division. Useful when the database doesn't contain large enough primes.
| n | Find prime greater than this value |
| std::domain_error | if n is too large (would overflow) |
Definition at line 161 of file primes.H.
References ah_domain_error_if, is_prime(), and max().
Referenced by next_prime().
| const unsigned long Primes::DefaultPrime = primeList[0] |
Default prime number used when no specific size is requested.
Definition at line 381 of file primes.C.
Referenced by OhashCommon< HashTbl, Key >::empty().
Number of primes in the pre-computed database.
Definition at line 379 of file primes.C.
Referenced by check_primes_database(), TEST(), and TEST().
| const unsigned long Primes::primeList |
Pre-computed array of prime numbers for fast lookup.
Definition at line 45 of file primes.C.
Referenced by check_primes_database(), next_prime(), TEST(), and TEST().