a DICTIONARY of strings on a compact trie
More...
#include <ADS/dictionary/Trie.h>
|
| 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 , const V & > |
| | a reference to an item
|
| using | const_reference = reference |
| | a constant reference to an item
|
| using | const_iterator = detail::TrieIterator< Node , V , true > |
| | the iterator on the items, constant
|
| using | iterator = const_iterator |
| | the iterator on the items
|
|
| std::optional< V > | lookup (std::string_view k) const |
| | the value of the key \( k \), or nothing, along the edges whose labels are pieces of \( k \)
|
| void | insert (std::string_view k, const V &v) |
| | associates the value \( v \) to the key \( k \)
|
| void | remove (std::string_view k) |
| | removes the key \( k \), if it is there, merging back a node left with a single child and no value
|
| bool | contains (std::string_view k) const |
| | true if the key \( k \) is there
|
| std::size_t | size (void) const |
| | the number of keys
|
| std::vector< std::string > | keysWithPrefix (std::string_view p) const |
| | the keys that begin with \( p \), in increasing order
|
| std::size_t | nodes (void) const |
| | the number of nodes, the root included
|
| 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::RadixTree< V >
a DICTIONARY of strings on a compact trie
◆ const_iterator
template<class V>
| using ADS::RadixTree< V >::const_iterator = detail::TrieIterator< Node , V , true > |
the iterator on the items, constant
◆ const_reference
a constant reference to an item
◆ difference_type
the type of the distances between two iterators
◆ iterator
the iterator on the items
◆ Key
◆ key_type
◆ mapped_type
◆ reference
◆ size_type
◆ Value
◆ value_type
the type of the items, for the standard library
◆ begin()
the iterator on the first item
◆ cbegin()
the constant iterator on the first item
◆ cend()
the constant iterator past the last item
◆ contains()
true if the key \( k \) is there
◆ end()
the iterator past the last item
◆ insert()
associates the value \( v \) to the key \( k \)
In pseudocode (the compact trie, section 6.3 of TAOCP, beyond the book), \( \lambda( y ) \) the label of the edge into \( y \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr
2 & \quad x \gets \mathit{root} \cr
3 & \quad \textbf{while}\ k \ne \varepsilon\ \textbf{do} \cr
4 & \qquad y \gets \text{the child of } x \text{ by } k[ 0 ] \cr
5 & \qquad \textbf{if}\ y = \textbf{nil}\ \textbf{then}\ \text{add a }
\text{leaf under } x \text{ labeled } k \text{ with } v;
\ \textbf{return}
\cr
6 & \qquad j \gets \text{the longest common prefix of } \lambda( y )
\text{ and } k \cr
7 & \qquad \textbf{if}\ j < |\lambda( y )|\ \textbf{then}\ \text{split }
\text{the edge into } y \text{ by a node } y' \text{ at } j;\ y \gets
y'
\cr
8 & \qquad k \gets k[ j .. ];\ x \gets y \cr
9 & \quad x.\mathit{value} \gets v
\end{array}}
\]
- Postcondition
- \( k \) has the value \( v \)
◆ keysWithPrefix()
template<class V>
| std::vector< std::string > ADS::RadixTree< V >::keysWithPrefix |
( |
std::string_view | p | ) |
const |
|
nodiscard |
the keys that begin with \( p \), in increasing order
◆ lookup()
template<class V>
| std::optional< V > ADS::RadixTree< V >::lookup |
( |
std::string_view | k | ) |
const |
|
nodiscard |
the value of the key \( k \), or nothing, along the edges whose labels are pieces of \( k \)
◆ nodes()
the number of nodes, the root included
◆ remove()
removes the key \( k \), if it is there, merging back a node left with a single child and no value
- Postcondition
- \( k \) is not there
◆ size()
The documentation for this class was generated from the following file: