Aleph-w 3.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

size_t Primes::next_prime (unsigned long n)
 Find the smallest prime number >= n from the database.
 
bool Primes::check_primes_database ()
 Verify the integrity 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:161
bool is_prime(unsigned long n)
Test if a number is prime using trial division.
Definition primes.H:128
size_t next_prime(unsigned long n)
Find the smallest prime number >= n from the database.
Definition primes.C:383
Prime number utilities for hash tables and mathematical operations.
See also
tpl_lhash.H Linear hash tables using primes
tpl_odhash.H Open-addressed hash tables
Author
Leandro Rabindranath León

Definition in file primes.H.