|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Functions | |
| unsigned long | next_prime (unsigned long n) |
| Find a prime >= n in the database, for hash table sizing. | |
| bool | check_primes_database () |
| Verify the order 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 | ( | ) |
Verify the order of the prime database.
Checks that every number in primeList is greater than the previous one, as the binary search of next_prime() needs. Used for testing and validation.
Definition at line 414 of file primes.C.
|
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 136 of file primes.H.
Referenced by next_prime(), next_prime_number_greater_than(), TEST(), TEST(), TEST(), TEST(), and TEST().
| unsigned long Primes::next_prime | ( | unsigned long | n | ) |
Find a prime >= n in the database, for hash table sizing.
Performs binary search on the pre-computed prime database, which holds only some of the primes. So the result is often larger than the smallest prime >= n: next_prime(2206) is 2309, although 2207 is prime. Below the first entry of the database (101) and above its last one, the result is the smallest prime >= n.
| n | Minimum value for the prime |
| std::domain_error | if no prime >= n fits in an unsigned long |
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(), main(), Aleph::GenLhashTable< Key, BucketType, Cmp >::make_default_lists(), hash_dry_detail::prime_table_len(), OhashCommon< HashTbl, Key >::rebuild_capacity(), Aleph::GenLhashTable< Key, BucketType, Cmp >::remove(), Aleph::GenLhashTable< Key, BucketType, Cmp >::search_or_insert(), OhashCommon< HashTbl, Key >::shrink_after_removal(), TEST(), TEST(), 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 171 of file primes.H.
References ah_domain_error_if, is_prime(), and max().
Referenced by next_prime(), and TEST().
| 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(), Aleph::Gen_Link_Cut_Tree_WithEdges< VT, ET, EdgeMonoid, LazyTag >::export_to_tree_node(), Aleph::GenLhashTable< Key, BucketType, Cmp >::make_default_lists(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST_F().
| 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(), TEST(), TEST(), and TEST().