Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
primes.H File Reference

Prime number utilities for hash tables and mathematical operations. More...

#include <cmath>
#include <ahDefs.H>
#include <ah-errors.H>
Include dependency graph for primes.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  Primes
 

Functions

unsigned long Primes::next_prime (unsigned long n)
 Find a prime >= n in the database, for hash table sizing.
 
bool Primes::check_primes_database ()
 Verify the order of the prime database.
 
bool Primes::is_prime (unsigned long n)
 Test if a number is prime using trial division.
 
unsigned long Primes::next_prime_number_greater_than (unsigned long n)
 Find the next prime strictly greater than n.
 

Detailed Description

Prime number utilities for hash tables and mathematical operations.

This file provides functions for working with prime numbers, primarily used for determining optimal hash table sizes. Prime-sized tables reduce clustering in hash collision resolution.

Features

  • Pre-computed prime number database for fast lookups
  • Primality testing via trial division
  • Next prime computation for dynamic sizing

Usage Example

#include <primes.H>
// Check if a number is prime
bool prime = Primes::is_prime(17); // true
// Get next prime for hash table sizing
size_t table_size = Primes::next_prime(1000); // Returns 1009
// Get next prime greater than n
unsigned long p = Primes::next_prime_number_greater_than(100); // 101
unsigned long next_prime_number_greater_than(unsigned long n)
Find the next prime strictly greater than n.
Definition primes.H:171
bool is_prime(unsigned long n)
Test if a number is prime using trial division.
Definition primes.H:136
unsigned long next_prime(unsigned long n)
Find a prime >= n in the database, for hash table sizing.
Definition primes.C:383
Prime number utilities for hash tables and mathematical operations.
See also
tpl_lhash.H Separate chaining hash tables
tpl_odhash.H Open-addressed hash tables
Author
Leandro Rabindranath León

Definition in file primes.H.