ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::PointerTable< T, Eq, A, Policy > Class Template Reference

a hash table of pointers to objects found by their keys, on the places of ADS (the inspection above), its insertions told through Policy More...

#include <ADS/dictionary/PointerTable.h>

Classes

struct  Places
 the places of the table, for SlotIterator More...

Public types

using Inserted = mod::Inserted< T * , std::uint64_t >
 an insertion of an object, its pointer the handle and its hash the key
using modifications = mod::list< Inserted , mod::Cleared , mod::Rebuilt >
 the events: an object inserted, the table emptied or rebuilt
using Subject
 the subject
using value_type = T *
 the type of the items, for the standard library
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances between two iterators
using reference = T *
 a reference to an item
using const_reference = T *
 a constant reference to an item
using const_iterator = SlotIterator< PointerTable , Places >
 the iterator on the items, constant
using iterator = const_iterator
 the iterator on the items

Public member functions

template<class... O>
requires ( ! kIndex )
 PointerTable (std::size_t capacity=16, Eq eq=Eq(), const A &alloc=A(), O &... o)
 a table of at least capacity places, a power of 2, at least 16, the static observers o...
template<class... O>
requires ( kIndex )
 PointerTable (std::size_t capacity, Eq eq, const A &alloc, L places, O &... o)
 the same on the store of places, with IndexPlaces
 PointerTable (const PointerTable &)=default
 a copy of the places, the objects shared
PointerTable & operator= (const PointerTable &)=default
 a copy of the places, the objects shared
 PointerTable (PointerTable &&o) noexcept
 the table of o, which is left empty, with no places until an insertion
PointerTable & operator= (PointerTable &&o) noexcept
 the table of o, which is left empty, as the constructor above
void clear (void)
 no object, the places kept; the objects are not touched
void reserve (std::size_t n)
 room for \( n \) objects with no growth, i.e., at least slotsFor( n ) places
template<class K, class Make>
std::pair< T *, bool > find_or_insert (const K &key, std::uint64_t hash, Make &&make)
 the object of the key, whose hash is hash, and false; if there is none, the object that make() returns, now in the table, and true
template<class K>
T * find (const K &key, std::uint64_t hash) const
 the object of the key, nil if there is none: the inspection of find_or_insert() up to the first empty place
void prefetch (std::uint64_t hash) const
 brings in the cache the first place of hash
std::size_t size (void) const
 the number of objects
std::size_t capacity (void) const
 the number of places
std::size_t bytes (void) const
 the memory of the places, in bytes
template<class F>
void forEach (F &&f) const
 f( p ) on each object, in the order of the places
Subject & subject (void)
 the subject, for ADS::batch() and ADS::quiet()
const Subject & subject (void) const
 the subject
template<class O>
requires ( Subject::dynamic )
int attach (O &o)
 attaches the observer \( o \) and gives its number
void detach (int id)
 detaches the observer number \( \mathit{id} \)
const_iterator begin (void) const
 the iterator on the first item
const_iterator end (void) const
 the iterator past the last item
const_iterator cbegin (void) const
 the constant iterator on the first item
const_iterator cend (void) const
 the constant iterator past the last item

Static public member functions

static constexpr std::size_t slotsFor (std::size_t n)
 the places that \( n \) objects need with no growth: the least power of 2, at least 16, above \( 10 n / 7 \), so that a table built with it, or reserved for \( n \), takes them all

Detailed description

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
class ADS::PointerTable< T, Eq, A, Policy >

a hash table of pointers to objects found by their keys, on the places of ADS (the inspection above), its insertions told through Policy

Member typedef documentation

◆ const_iterator

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::const_iterator = SlotIterator< PointerTable , Places >

the iterator on the items, constant

◆ const_reference

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::const_reference = T *

a constant reference to an item

◆ difference_type

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::difference_type = std::ptrdiff_t

the type of the distances between two iterators

◆ Inserted

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::Inserted = mod::Inserted< T * , std::uint64_t >

an insertion of an object, its pointer the handle and its hash the key

◆ iterator

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::iterator = const_iterator

the iterator on the items

◆ modifications

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::modifications = mod::list< Inserted , mod::Cleared , mod::Rebuilt >

the events: an object inserted, the table emptied or rebuilt

◆ reference

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::reference = T *

a reference to an item

◆ size_type

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::size_type = std::size_t

the type of the sizes

◆ Subject

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::Subject
Initial value:
typename Policy::template bind< modifications ,
mod::list< Inserted, Erased, Assigned, mod::Cleared, mod::Rebuilt > modifications
the events: a key inserted or erased with its value, its value changed, the map emptied or rebuilt
Definition DenseHashMap.h:188
PointerTable(std::size_t capacity=16, Eq eq=Eq(), const A &alloc=A(), O &... o)
a table of at least capacity places, a power of 2, at least 16, the static observers o....
Definition PointerTable.h:287

the subject

◆ value_type

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
using ADS::PointerTable< T, Eq, A, Policy >::value_type = T *

the type of the items, for the standard library

Constructor and destructor documentation

◆ PointerTable() [1/4]

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
template<class... O>
requires ( ! kIndex )
ADS::PointerTable< T, Eq, A, Policy >::PointerTable ( std::size_t capacity = 16,
Eq eq = Eq(),
const A & alloc = A(),
O &... o )
inlineexplicit

a table of at least capacity places, a power of 2, at least 16, the static observers o...

◆ PointerTable() [2/4]

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
template<class... O>
requires ( kIndex )
ADS::PointerTable< T, Eq, A, Policy >::PointerTable ( std::size_t capacity,
Eq eq,
const A & alloc,
L places,
O &... o )
inline

the same on the store of places, with IndexPlaces

◆ PointerTable() [3/4]

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
ADS::PointerTable< T, Eq, A, Policy >::PointerTable ( const PointerTable< T, Eq, A, Policy > & )
default

a copy of the places, the objects shared

◆ PointerTable() [4/4]

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
ADS::PointerTable< T, Eq, A, Policy >::PointerTable ( PointerTable< T, Eq, A, Policy > && o)
noexcept

the table of o, which is left empty, with no places until an insertion

Member function documentation

◆ attach()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
template<class O>
requires ( Subject::dynamic )
int ADS::PointerTable< T, Eq, A, Policy >::attach ( O & o)
inline

attaches the observer \( o \) and gives its number

Precondition
no batch is open

◆ begin()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
const_iterator ADS::PointerTable< T, Eq, A, Policy >::begin ( void ) const
nodiscard

the iterator on the first item

◆ bytes()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
std::size_t ADS::PointerTable< T, Eq, A, Policy >::bytes ( void ) const
nodiscard

the memory of the places, in bytes

◆ capacity()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
std::size_t ADS::PointerTable< T, Eq, A, Policy >::capacity ( void ) const
nodiscard

the number of places

◆ cbegin()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
const_iterator ADS::PointerTable< T, Eq, A, Policy >::cbegin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cend()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
const_iterator ADS::PointerTable< T, Eq, A, Policy >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ clear()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
void ADS::PointerTable< T, Eq, A, Policy >::clear ( void )

no object, the places kept; the objects are not touched

◆ detach()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
void ADS::PointerTable< T, Eq, A, Policy >::detach ( int id)
inline

detaches the observer number \( \mathit{id} \)

Precondition
it is attached, no batch is open

◆ end()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
const_iterator ADS::PointerTable< T, Eq, A, Policy >::end ( void ) const
nodiscard

the iterator past the last item

◆ find()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
template<class K>
T * ADS::PointerTable< T, Eq, A, Policy >::find ( const K & key,
std::uint64_t hash ) const
nodiscard

the object of the key, nil if there is none: the inspection of find_or_insert() up to the first empty place

◆ find_or_insert()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
template<class K, class Make>
std::pair< T *, bool > ADS::PointerTable< T, Eq, A, Policy >::find_or_insert ( const K & key,
std::uint64_t hash,
Make && make )

the object of the key, whose hash is hash, and false; if there is none, the object that make() returns, now in the table, and true

In pseudocode (the linear inspection of section 6.4 of TAOCP, beyond the book), \( S[ 0 .. m - 1 ] \) the places, \( m \) a power of 2, each with a hash and a pointer:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{findOrInsert}( \mathit{key} , h , \mathit{make} ) \cr 2 & \quad i \gets \mathrm{fibonacciPlace}( h , \log_2 m ) \cr 3 & \quad \textbf{while}\ S[ i ].p \ne \textbf{nil}\ \textbf{do} \cr 4 & \qquad \textbf{if}\ S[ i ].h = h\ \textbf{and}\ \mathrm{eq}( S[ i ].p , \mathit{key} )\ \textbf{then return}\ ( S[ i ].p , \textbf{false} ) \cr 5 & \qquad i \gets ( i + 1 ) \bmod m \cr 6 & \quad S[ i ] \gets ( h , \mathit{make}() );\ n \gets n + 1 \cr 7 & \quad \textbf{if}\ 10 n > 7 m\ \textbf{then}\ \text{double the } \text{places, each reinserted from the first place of its hash} \cr 8 & \quad \textbf{return}\ ( S[ i ].p , \textbf{true} ) \end{array}} \]

Postcondition
the result is not nil

◆ forEach()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
template<class F>
void ADS::PointerTable< T, Eq, A, Policy >::forEach ( F && f) const

f( p ) on each object, in the order of the places

◆ operator=() [1/2]

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
PointerTable & ADS::PointerTable< T, Eq, A, Policy >::operator= ( const PointerTable< T, Eq, A, Policy > & )
default

a copy of the places, the objects shared

◆ operator=() [2/2]

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
PointerTable & ADS::PointerTable< T, Eq, A, Policy >::operator= ( PointerTable< T, Eq, A, Policy > && o)
noexcept

the table of o, which is left empty, as the constructor above

◆ prefetch()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
void ADS::PointerTable< T, Eq, A, Policy >::prefetch ( std::uint64_t hash) const

brings in the cache the first place of hash

◆ reserve()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
void ADS::PointerTable< T, Eq, A, Policy >::reserve ( std::size_t n)

room for \( n \) objects with no growth, i.e., at least slotsFor( n ) places

◆ size()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
std::size_t ADS::PointerTable< T, Eq, A, Policy >::size ( void ) const
nodiscard

the number of objects

◆ slotsFor()

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
constexpr std::size_t ADS::PointerTable< T, Eq, A, Policy >::slotsFor ( std::size_t n)
inlinestaticnodiscardconstexpr

the places that \( n \) objects need with no growth: the least power of 2, at least 16, above \( 10 n / 7 \), so that a table built with it, or reserved for \( n \), takes them all

◆ subject() [1/2]

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
Subject & ADS::PointerTable< T, Eq, A, Policy >::subject ( void )
inlinenodiscard

the subject, for ADS::batch() and ADS::quiet()

◆ subject() [2/2]

template<class T, class Eq = StateEqual, class A = std::allocator< std::byte >, class Policy = NoObservers>
const Subject & ADS::PointerTable< T, Eq, A, Policy >::subject ( void ) const
inlinenodiscard

the subject


The documentation for this class was generated from the following file: