a DICTIONARY of strings on a 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 , false > |
| | 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, in \( O( |k| \log \sigma ) \) time
|
| void | insert (std::string_view k, const V &v) |
| | associates the value \( v \) to the key \( k \), the path of \( k \) made by the nodes missing, in \( O( |k| \log \sigma ) \) time
|
| void | remove (std::string_view k) |
| | removes the key \( k \), if it is there, and the nodes of its path left with no value and no child, bottom up
|
| 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: those below the node of \( p \)
|
| 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::Trie< V >
a DICTIONARY of strings on a trie
◆ const_iterator
template<class V>
| using ADS::Trie< V >::const_iterator = detail::TrieIterator< Node , V , false > |
the iterator on the items, constant
◆ const_reference
a constant reference to an item
◆ difference_type
template<class V>
| using ADS::Trie< V >::difference_type = std::ptrdiff_t |
the type of the distances between two iterators
◆ iterator
the iterator on the items
◆ Key
◆ key_type
◆ mapped_type
◆ reference
◆ size_type
template<class V>
| using ADS::Trie< V >::size_type = std::size_t |
◆ Value
◆ value_type
template<class V>
| using ADS::Trie< V >::value_type = std::pair< std::string , V > |
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()
template<class V>
| bool ADS::Trie< V >::contains |
( |
std::string_view | k | ) |
const |
|
nodiscard |
true if the key \( k \) is there
◆ end()
the iterator past the last item
◆ insert()
template<class V>
| void ADS::Trie< V >::insert |
( |
std::string_view | k, |
|
|
const V & | v ) |
associates the value \( v \) to the key \( k \), the path of \( k \) made by the nodes missing, in \( O( |k| \log \sigma ) \) time
- Postcondition
- \( k \) has the value \( v \)
◆ keysWithPrefix()
template<class V>
| std::vector< std::string > ADS::Trie< V >::keysWithPrefix |
( |
std::string_view | p | ) |
const |
|
nodiscard |
the keys that begin with \( p \), in increasing order: those below the node of \( p \)
◆ lookup()
template<class V>
| std::optional< V > ADS::Trie< V >::lookup |
( |
std::string_view | k | ) |
const |
|
nodiscard |
the value of the key \( k \), or nothing, in \( O( |k| \log \sigma ) \) time
In pseudocode (Fredkin, section 6.3 of TAOCP, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{lookup}( k ) \cr
2 & \quad x \gets \mathit{root} \cr
3 & \quad \textbf{foreach}\ \text{character } c \text{ of } k
\ \textbf{do} \cr
4 & \qquad x \gets \text{the child of } x \text{ by } c;\ \textbf{if}\ x
= \textbf{nil}\ \textbf{then return nil} \cr
5 & \quad \textbf{return}\ x.\mathit{value}
\end{array}}
\]
◆ nodes()
template<class V>
| std::size_t ADS::Trie< V >::nodes |
( |
void | | ) |
const |
|
nodiscard |
the number of nodes, the root included
◆ remove()
template<class V>
| void ADS::Trie< V >::remove |
( |
std::string_view | k | ) |
|
removes the key \( k \), if it is there, and the nodes of its path left with no value and no child, bottom up
- Postcondition
- \( k \) is not there
◆ size()
template<class V>
| std::size_t ADS::Trie< V >::size |
( |
void | | ) |
const |
|
nodiscard |
The documentation for this class was generated from the following file: