ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
TableSize.h File Reference

The sizes of the hash tables that restructure themselves (section 7.4): a size that is a power of two doubles or halves, any other one goes to the first prime not smaller than its double or its half, so that the inspections of an OpenHashTable that need a prime size, or a size coprime with their step, keep working. More...

#include "ADS/Contract.h"
#include <algorithm>
#include <concepts>
#include <cstddef>
#include "ADS/dictionary/impl/TableSize.tpp"

Go to the source code of this file.

Namespaces

namespace  ADS

Concepts

concept  ADS::PlaceHash
 a hash \( H \) that maps a key straight to a place of a table of \( m = 2^d \) places by h.place( k , m ), as the multiplicative hashing of section 5.1.1 of Morin's book and the tabulation hashing of its section 5.2.3 do with the \( d \) most significant bits of a product or of a XOR [see MultiplicativeHash in UniversalHashing.h and TabulationHash in RandomHashing.h]; the tables use it in place of \( h( k ) \bmod m \), whose low bits are the worst ones of a product

Functions

bool ADS::is_prime (std::size_t n)
 true if \( n \) is prime, by trial division up to \( \sqrt{n} \)
std::size_t ADS::next_prime (std::size_t n)
 the smallest prime not smaller than \( n \), by trial divisions
bool ADS::is_pow2 (std::size_t n)
 true if \( n \) is a power of two, i.e., \( n \ne 0 \) and n & ( n - 1 ) is 0
std::size_t ADS::resized (std::size_t m, bool grow, std::size_t m0)
 the size after a doubling, or after a halving down to \( m_0 \)

Detailed description

The sizes of the hash tables that restructure themselves (section 7.4): a size that is a power of two doubles or halves, any other one goes to the first prime not smaller than its double or its half, so that the inspections of an OpenHashTable that need a prime size, or a size coprime with their step, keep working.

By the theorem of Chebyshev there is a prime between \( x \) and \( 2 x \), so that the next prime is less than twice the size asked, and it is found by trial divisions in \( O( \sqrt{m} ) \) each.

The contracts [see Contract.h]: resized() starts from a size not below the initial size \( m_0 > 0 \), never goes below it, and keeps a power of two a power of two. The functions are defined in TableSize.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, section 7.4, https://algoritmicamente.it/materiali/libro/capitoli/cap07.pdf
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa