|
| using | Key = std::string |
| | the type of the keys
|
| using | Value = V |
| | the type of the values
|
| using | value_type = std::pair< std::string , V > |
| | the type of the items, for the standard library
|
| using | key_type = std::string |
| | the type of the keys
|
| using | mapped_type = V |
| | the type of the values
|
| 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 = PairRef< std::string_view , const V & , std::string > |
| | a reference to an item
|
| using | const_reference = reference |
| | a constant reference to an item
|
| using | iterator = const_iterator |
| | the iterator on the items
|
|
| | AdaptiveRadixTree (void)=default |
| | the empty tree
|
| | AdaptiveRadixTree (const AdaptiveRadixTree &o) |
| | a copy of other
|
| | AdaptiveRadixTree (AdaptiveRadixTree &&o) noexcept |
| | the items of other, which is left empty
|
| AdaptiveRadixTree & | operator= (AdaptiveRadixTree o) noexcept |
| | the assignment, by copy and swap
|
| | ~AdaptiveRadixTree () |
| | frees the memory of the structure
|
| std::optional< V > | lookup (std::string_view k) const |
| | the value of \( k \), if there
|
| const V * | find (std::string_view k) const |
| | the value of \( k \), or nil, by the search of lookup()
|
| V * | find (std::string_view k) |
| | the value of \( k \), to change in place, or nil
|
| bool | insert (std::string_view k, const V &v) |
| | gives \( k \) the value \( v \); true if \( k \) was not there
|
| bool | remove (std::string_view k) |
| | removes \( k \), shrinking its node to the previous layout when that keeps about a quarter of its places free and merging a node left with a single child into its prefix; true if it was there
|
| bool | contains (std::string_view k) const |
| | true if \( k \) is there
|
| std::size_t | size (void) const |
| | the number of keys
|
| bool | empty (void) const |
| | true if there are no keys
|
| void | clear (void) |
| | removes all the keys
|
| void | swap (AdaptiveRadixTree &o) noexcept |
| | exchanges the contents with other in \( O( 1 ) \)
|
| template<class F> |
| void | forEach (F &&f) const |
| | f( key , value ) on each pair, by increasing keys
|
| template<class F> |
| void | forPrefix (std::string_view p, F &&f) const |
| | f( key , value ) on each pair whose key begins with \( p \), by increasing keys
|
| std::vector< std::string > | keysWithPrefix (std::string_view p) const |
| | the keys that begin with \( p \), in increasing order
|
| 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 V>
class ADS::AdaptiveRadixTree< V >
an ordered map from strings to values of type V on an adaptive radix tree
gives \( k \) the value \( v \); true if \( k \) was not there
In pseudocode (Leis, Kemper and Neumann, beyond the book), the two passes of the file; a node full grows to the next layout:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{insert}( k , v ) \cr
2 & \quad \text{descend as } \mathrm{search}( k ) \text{, to where it }
\text{stops} \cr
3 & \quad \textbf{if}\ \text{no prefix on the way was longer than 8 }
\text{bytes}\ \textbf{then} \cr
4 & \qquad \text{put } k \text{ there: a child, the key of a node, or a }
\text{new node splitting a leaf or a prefix} \cr
5 & \quad \textbf{else} \cr
6 & \qquad l \gets \text{a leaf below the last node reached};\ c \gets
\text{the bytes that } k \text{ shares with } l \cr
7 & \qquad \text{descend again to the node or the leaf that parts at } c
\text{, and put } k \text{ there} \cr
8 & \quad \textbf{return}\ \text{whether } k \text{ is new}
\end{array}}
\]
the value of \( k \), if there
In pseudocode (Leis, Kemper and Neumann, beyond the book), \( d \) the bytes of \( k \) consumed; a prefix is compared on its first 8 bytes only (the optimistic compression), the leaf on the whole key:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{search}( k ) \cr
2 & \quad p \gets \mathit{root};\ d \gets 0 \cr
3 & \quad \textbf{while}\ p \ne \textbf{nil}\ \textbf{do} \cr
4 & \qquad \textbf{if}\ p \text{ is a leaf }\ \textbf{then return}\ p
\ \text{if its key is } k \text{, else } \textbf{nil} \cr
5 & \qquad \textbf{if}\ \text{the prefix of } p \text{ does not match } k[
d .. ]\ \textbf{then return nil} \cr
6 & \qquad d \gets d + \text{the length of the prefix} \cr
7 & \qquad \textbf{if}\ d = |k|\ \textbf{then return}
\ \text{the key that } \text{ends at } p \text{, if it is } k \cr
8 & \qquad p \gets \text{the child of } p \text{ by } k[ d ];\ d \gets d +
1\quad \triangleright\ \text{by the layout of } p
\end{array}}
\]