a hash map with its pairs in a dense vector and an index of positions, its changes told through Policy
More...
|
| using | Key = K |
| | the type of the keys
|
| using | Value = V |
| | the type of the values
|
| using | Inserted = mod::Inserted< K , K , V > |
| | an insertion of a key, the key its handle
|
| using | Erased = mod::Erased< K , K , V > |
| | an erasure of a key, told before the removal
|
| using | Assigned = mod::Assigned< K , V > |
| | a change of the value of a key
|
| using | modifications |
| | the events: a key inserted or erased with its value, its value changed, the map emptied or rebuilt
|
| using | Subject |
| | the subject
|
| using | value_type = std::pair< K , V > |
| | 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 = const std::pair< K , V > & |
| | a reference to an item
|
| using | const_reference = const std::pair< K , V > & |
| | a constant reference to an item
|
| using | const_iterator |
| | the iterator on the items, constant
|
| using | iterator = const_iterator |
| | the iterator on the items
|
| using | allocator_type = A |
| | the type of the allocator
|
|
| template<class... O> |
| | DenseHashMap (std::size_t n=0, H h=H(), Eq eq=Eq(), const A &alloc=A(), O &... o) |
| | the empty map, with room for \( n \) pairs before it grows, its pairs and groups from alloc, the static observers o...
|
| | DenseHashMap (const DenseHashMap &o) |
| | a copy of other, on the allocator that select_on_container_copy_construction() gives
|
| | DenseHashMap (const DenseHashMap &o, const A &alloc) |
| | a copy of other, on alloc
|
| | DenseHashMap (DenseHashMap &&o) noexcept |
| | the pairs of o, which is left empty, with no places
|
| | DenseHashMap (DenseHashMap &&o, const A &alloc) |
| | the pairs of o, which is left empty, on alloc: moved one by one if the allocators are not equal
|
| DenseHashMap & | operator= (DenseHashMap o) noexcept |
| | the assignment, by copy and swap, when the allocators are all equal
|
| DenseHashMap & | operator= (const DenseHashMap &o) |
| | the copy assignment, with the allocator of o if it propagates
|
| DenseHashMap & | operator= (DenseHashMap &&o) |
| | the move assignment: the memory of o if its allocator propagates or is equal, else its pairs moved one by one
|
| | ~DenseHashMap ()=default |
| | frees the pairs and the groups
|
| std::optional< V > | lookup (const K &k) const |
| | the value of the key \( k \), or nothing
|
| const V * | find (const K &k) const |
| | the value of the key \( k \), nil if it is not there
|
| V * | find (const K &k) |
| | the value of the key \( k \), to change in place, nil if it is not there
|
| bool | insert (const K &k, const V &v) |
| | associates the value \( v \) to the key \( k \); true if \( k \) was not there
|
| bool | insert (K &&k, V &&v) |
| | as insert( k , v ), moving the key and the value
|
| template<class... Args> |
| std::pair< V *, bool > | try_emplace (const K &k, Args &&... a) |
| | the value of the key \( k \), built from a if \( k \) was not there, and true in that case; a key already there keeps its value and a is not touched.
|
| template<class... Args> |
| std::pair< V *, bool > | try_emplace (K &&k, Args &&... a) |
| | as try_emplace( k , a ), moving the key
|
| bool | remove (const K &k) |
| | removes the key \( k \), if it is there, moving the last pair into its position; true if it was
|
| bool | contains (const K &k) const |
| | true if the key \( k \) is there
|
| std::size_t | size (void) const |
| | the number \( n \) of pairs
|
| bool | empty (void) const |
| | true if there are no pairs
|
| std::size_t | capacity (void) const |
| | the number of places of the index, 12 times 0 or a power of 2 at least 2
|
| double | load (void) const |
| | the load factor \( n / m \) of the index, 0 with no places
|
| std::size_t | deleted (void) const |
| | the places of the index emptied by remove() in groups that some inspection went past, which count as full until the index is rebuilt; \( O( 1 ) \) time, the count kept by the operations
|
| void | reserve (std::size_t n) |
| | room for \( n \) pairs before the map grows
|
| void | clear (void) |
| | removes all the pairs, keeping the places
|
| template<class F> |
| void | forEach (F &&f) const |
| | f( k , v ) on the pairs, in the order of the vector
|
| const std::pair< K, V > * | data (void) const |
| | the pairs, in the order of the vector
|
| void | swap (DenseHashMap &o) noexcept(detail::swapNoexcept< A >) |
| | exchanges the contents with other in \( O( 1 ) \), and the allocators if they propagate on a swap
|
| 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} \)
|
| allocator_type | get_allocator (void) const |
| | the allocator of the pairs and of the groups
|
| 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 K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >, class Policy = NoObservers>
class ADS::DenseHashMap< K, V, H, Eq, A, Policy >
a hash map with its pairs in a dense vector and an index of positions, its changes told through Policy
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >, class Policy = NoObservers>
| bool ADS::DenseHashMap< K, V, H, Eq, A, Policy >::insert |
( |
const K & | k, |
|
|
const V & | v ) |
associates the value \( v \) to the key \( k \); true if \( k \) was not there
In pseudocode (beyond the book), the inspection of lookup():
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{insert}( k , v ) \cr
2 & \quad \textbf{if}\ k \text{ is there }\ \textbf{then}\ \text{give it }
\text{the value } v;\ \textbf{return false} \cr
3 & \quad \textbf{if}\ \text{the places full or counted reach }
7 m / 8\ \textbf{then}\ \text{rebuild the index} \cr
4 & \quad ( g , j ) \gets \text{the first empty place of the inspection,}
\text{ with } \beta \text{ set in the overflow of the full groups}
\text{ passed} \cr
5 & \quad \text{append } ( k , v ) \text{ to } A;
\ \text{the control byte } \text{of } j \gets t;\ g.\mathit{at}[ j ]
\gets |A| - 1 \cr
6 & \quad \textbf{return true}
\end{array}}
\]
- Postcondition
- \( k \) is in the map
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >, class Policy = NoObservers>
| std::optional< V > ADS::DenseHashMap< K, V, H, Eq, A, Policy >::lookup |
( |
const K & | k | ) |
const |
|
nodiscard |
the value of the key \( k \), or nothing
In pseudocode (the groups of Kulukundis and the overflow of Lopez Munoz, beyond the book), \( x \) the mixed hash of \( k \), \( t \) its fingerprint, \( \beta \) its bit of overflow and \( A \) the vector of the pairs:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{lookup}( k ) \cr
2 & \quad g \gets \text{the top bits of } x;\ i \gets 0 \cr
3 & \quad \textbf{loop} \cr
4 & \qquad \textbf{foreach}\ \text{place } j \text{ of the group } g
\text{ whose control byte is } t\ \textbf{do} \cr
5 & \qquad\quad \textbf{if}\ A[ g.\mathit{at}[ j ] ].\mathit{key} = k
\ \textbf{then return}\ A[ g.\mathit{at}[ j ] ].\mathit{value} \cr
6 & \qquad \textbf{if}\ \text{the overflow of } g \text{ lacks } \beta
\ \textbf{then return nil} \cr
7 & \qquad i \gets i + 1;\ g \gets ( g + i ) \bmod G\quad
\triangleright\ \text{the triangular order}
\end{array}}
\]
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >, class Policy = NoObservers>
removes the key \( k \), if it is there, moving the last pair into its position; true if it was
In pseudocode (beyond the book), \( p \) the position of \( k \) in \( A \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{remove}( k ) \cr
2 & \quad ( g , j ) \gets \text{the place of } k;\ \textbf{if}
\ \text{none } \textbf{then return false} \cr
3 & \quad p \gets g.\mathit{at}[ j ];\ \text{empty the place } j
\text{ of } g \cr
4 & \quad \textbf{if}\ p < |A| - 1\ \textbf{then} \cr
5 & \qquad \text{the place of } A[ |A| - 1 ]
\text{, by the inspection of } \text{its key, takes } p \cr
6 & \qquad A[ p ] \gets A[ |A| - 1 ] \cr
7 & \quad \text{remove the last pair of } A;\ \textbf{return true}
\end{array}}
\]
- Postcondition
- \( k \) is not in the map