ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::RadixTree< V > Class Template Reference

a DICTIONARY of strings on a compact trie More...

#include <ADS/dictionary/Trie.h>

Public types

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

Public member functions

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

Detailed description

template<class V>
class ADS::RadixTree< V >

a DICTIONARY of strings on a compact trie

Member typedef documentation

◆ const_iterator

template<class V>
using ADS::RadixTree< V >::const_iterator = detail::TrieIterator< Node , V , true >

the iterator on the items, constant

◆ const_reference

template<class V>
using ADS::RadixTree< V >::const_reference = reference

a constant reference to an item

◆ difference_type

template<class V>
using ADS::RadixTree< V >::difference_type = std::ptrdiff_t

the type of the distances between two iterators

◆ iterator

template<class V>
using ADS::RadixTree< V >::iterator = const_iterator

the iterator on the items

◆ Key

template<class V>
using ADS::RadixTree< V >::Key = std::string

the type of the keys

◆ key_type

template<class V>
using ADS::RadixTree< V >::key_type = std::string

the type of the keys

◆ mapped_type

template<class V>
using ADS::RadixTree< V >::mapped_type = V

the type of the values

◆ reference

template<class V>
using ADS::RadixTree< V >::reference = PairRef< std::string , const V & >

a reference to an item

◆ size_type

template<class V>
using ADS::RadixTree< V >::size_type = std::size_t

the type of the sizes

◆ Value

template<class V>
using ADS::RadixTree< V >::Value = V

the type of the values

◆ value_type

template<class V>
using ADS::RadixTree< V >::value_type = std::pair< std::string , V >

the type of the items, for the standard library

Member function documentation

◆ begin()

template<class V>
const_iterator ADS::RadixTree< V >::begin ( void ) const
inlinenodiscard

the iterator on the first item

◆ cbegin()

template<class V>
const_iterator ADS::RadixTree< V >::cbegin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cend()

template<class V>
const_iterator ADS::RadixTree< V >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ contains()

template<class V>
bool ADS::RadixTree< V >::contains ( std::string_view k) const
nodiscard

true if the key \( k \) is there

◆ end()

template<class V>
const_iterator ADS::RadixTree< V >::end ( void ) const
inlinenodiscard

the iterator past the last item

◆ insert()

template<class V>
void ADS::RadixTree< V >::insert ( std::string_view k,
const V & v )

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()

template<class V>
std::size_t ADS::RadixTree< V >::nodes ( void ) const
nodiscard

the number of nodes, the root included

◆ remove()

template<class V>
void ADS::RadixTree< V >::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

Postcondition
\( k \) is not there

◆ size()

template<class V>
std::size_t ADS::RadixTree< V >::size ( void ) const
nodiscard

the number of keys


The documentation for this class was generated from the following file: