a DICTIONARY that one thread writes and many threads read at once, by linear probing on atomic words, with no read-modify-write per insertion, readers that read on while it grows, and no removal; cleared in \( O( 1 ) \) by the policy EpochClear
More...
|
| | SingleWriterFlatTable (std::size_t n=0, H h=H(), Eq eq=Eq()) |
| | the table of the least vector that holds \( n \) pairs with no growth, at least 64 places
|
| | SingleWriterFlatTable (const SingleWriterFlatTable &)=delete |
| SingleWriterFlatTable & | operator= (const SingleWriterFlatTable &)=delete |
| std::uint64_t | hash (const K &k) const |
| | the hash of 64 bits of \( k \), that the operations take
|
| std::pair< V, bool > | findOrInsert (const K &k, std::uint64_t h, const V &v) |
| | the value held for the key \( k \) of hash \( h \), which is \( v \) if absent and then inserted, and true if it was inserted; by the writer only
|
| std::pair< V, bool > | findOrInsert (const K &k, const V &v) |
| | findOrInsert() above, with the hash computed
|
| std::pair< K, bool > | findOrInsertKey (const K &k, std::uint64_t h) |
| | the key held equal to \( k \) by Eq, of hash \( h \), which is \( k \) itself if absent and then inserted; true if it was inserted, for a set (an empty value); by the writer only
|
| bool | insert (const K &k, const V &v) |
| | true if the key \( k \) was absent and \( ( k , v ) \) inserted; by the writer only
|
template<class F>
requires ( valueBytes() > 0 ) |
| bool | update (const K &k, F &&f) |
| | the value of the key \( k \) replaced by f( value ), true if the key is there, by a store with release that a reader sees whole; by the writer only
|
| std::optional< V > | find (const K &k, std::uint64_t h) const |
| | a copy of the value of the key \( k \) of hash \( h \), or nothing; by any thread, also while the writer inserts and grows the table
|
| std::optional< V > | find (const K &k) const |
| | find() above, with the hash computed
|
| std::optional< K > | findKey (const K &k, std::uint64_t h) const |
| | a copy of the key held equal to \( k \) by Eq, of hash \( h \), or nothing, by the lookup of find(); by any thread
|
| std::optional< K > | findKey (const K &k) const |
| | findKey() above, with the hash computed
|
| bool | contains (const K &k, std::uint64_t h) const |
| | whether the key \( k \) of hash \( h \) is there; by any thread
|
| bool | contains (const K &k) const |
| | contains() above, with the hash computed
|
| std::size_t | size (void) const |
| | the pairs: exact for the writer, and for another thread a number of pairs that the table held at some time since its last clear()
|
| bool | empty (void) const |
| | whether there is no pair
|
| std::size_t | capacity (void) const |
| | the places of the vector in use
|
| std::size_t | rehashes (void) const |
| | the growths made so far
|
| void | reserve (std::size_t n) |
| | the table grown so that it holds \( n \) pairs with no growth; by the writer only
|
| void | clear (void) |
| | no pair, in time linear in the places, or \( O( 1 ) \) with EpochClear but once per \( 2^{|S|} - 2 \) calls; the vectors replaced are freed
|
| std::uint64_t | epoch (void) const |
| | the epoch of the policy EpochClear, 1 for ZeroingClear
|
| template<class F> |
| void | forEach (F &&f) const |
| | f( k , v ) on each pair, in no order
|
| bool | consistent (void) const |
| | whether each key is reached from its place with no free place in between, once, and the pairs are those counted
|
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class C = ZeroingClear>
class ADS::SingleWriterFlatTable< K, V, H, Eq, C >
a DICTIONARY that one thread writes and many threads read at once, by linear probing on atomic words, with no read-modify-write per insertion, readers that read on while it grows, and no removal; cleared in \( O( 1 ) \) by the policy EpochClear
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class C = ZeroingClear>
a copy of the value of the key \( k \) of hash \( h \), or nothing; by any thread, also while the writer inserts and grows the table
In pseudocode (beyond the book), with the notation of findOrInsert() above:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{find}( k , h ) \cr
2 & \quad \textbf{loop} \cr
3 & \qquad T \gets \text{the vector in use } W\quad \triangleright
\ \text{acquire} \cr
4 & \qquad i \gets \lfloor h / 2^{64 - l} \rfloor \cr
5 & \qquad \textbf{while}\ \text{the group of } i \text{ is in use}
\ \textbf{and}\ T[ i ].\mathit{key} \ne 0\ \textbf{do}\quad
\triangleright\ \text{acquire} \cr
6 & \qquad\quad \textbf{if}\ T[ i ].\mathit{key} = k\ \textbf{then}
\ \textbf{return}\ T[ i ].\mathit{value} \cr
7 & \qquad\quad i \gets ( i + 1 ) \bmod 2^l \cr
8 & \qquad \textbf{if}\ T \text{ is still the vector in use}
\ \textbf{then return nil}
\end{array}}
\]
- Precondition
- hash( k ) is \( h \) (audit)
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class C = ZeroingClear>
the value held for the key \( k \) of hash \( h \), which is \( v \) if absent and then inserted, and true if it was inserted; by the writer only
In pseudocode (beyond the book), \( W \) the vector in use, of \( 2^l \) places, and \( n \) the pairs:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{findOrInsert}( k , h , v ) \cr
2 & \quad \textbf{if}\ 2 ( n + 1 ) > 2^l\ \textbf{then}
\ \mathrm{grow}() \cr
3 & \quad i \gets \lfloor h / 2^{64 - l} \rfloor \cr
4 & \quad \textbf{loop} \cr
5 & \qquad \textbf{if}\ \text{the group of } i \text{ is out of use}
\ \textbf{then}\ \text{write 0 to its words; store the epoch as}
\text{ its stamp}\quad \triangleright\ \text{release} \cr
6 & \qquad \textbf{if}\ W[ i ].\mathit{key} = 0\ \textbf{then} \cr
7 & \qquad\quad W[ i ].\mathit{value} \gets v;\ W[ i ].\mathit{key}
\gets k\quad \triangleright\ \text{the key with release} \cr
8 & \qquad\quad n \gets n + 1;\ \textbf{return}\ ( v ,
\textbf{true} ) \cr
9 & \qquad \textbf{if}\ W[ i ].\mathit{key} = k\ \textbf{then}
\ \textbf{return}\ ( W[ i ].\mathit{value} , \textbf{false} ) \cr
10 & \qquad i \gets ( i + 1 ) \bmod 2^l \cr
11 & \textbf{procedure}\ \mathrm{grow}() \cr
12 & \quad W' \gets \text{a vector of } 2^{l + 1} \text{ free places}
\cr
13 & \quad \textbf{foreach}\ \text{pair } ( k , v ) \text{ of } W
\ \textbf{do}\ \text{put it at the first free place of } k
\text{ in } W' \cr
14 & \quad \text{keep } W \text{ for the readers};\ W \gets W'\quad
\triangleright\ \text{release}
\end{array}}
\]
- Precondition
- the caller is the writer; hash( k ) is \( h \) (audit)
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class C = ZeroingClear>
template<class F>
requires ( valueBytes() > 0 )
the value of the key \( k \) replaced by f( value ), true if the key is there, by a store with release that a reader sees whole; by the writer only
- Precondition
- the caller is the writer