|
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
|
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
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...
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 |
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
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