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

an ordered map from strings to values of type V on an adaptive radix tree More...

#include <ADS/dictionary/AdaptiveRadixTree.h>

Classes

class  const_iterator
 the iterator on the pairs by increasing keys, by a stack of the nodes on the way to a leaf More...

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_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

Public member functions

 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

Detailed description

template<class V>
class ADS::AdaptiveRadixTree< V >

an ordered map from strings to values of type V on an adaptive radix tree

Member typedef documentation

◆ const_reference

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

a constant reference to an item

◆ difference_type

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

the type of the distances between two iterators

◆ iterator

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

the iterator on the items

◆ Key

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

the type of the keys

◆ key_type

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

the type of the keys

◆ mapped_type

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

the type of the values

◆ reference

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

a reference to an item

◆ size_type

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

the type of the sizes

◆ Value

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

the type of the values

◆ value_type

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

the type of the items, for the standard library

Constructor and destructor documentation

◆ AdaptiveRadixTree() [1/3]

template<class V>
ADS::AdaptiveRadixTree< V >::AdaptiveRadixTree ( void )
default

the empty tree

◆ AdaptiveRadixTree() [2/3]

template<class V>
ADS::AdaptiveRadixTree< V >::AdaptiveRadixTree ( const AdaptiveRadixTree< V > & o)

a copy of other

◆ AdaptiveRadixTree() [3/3]

template<class V>
ADS::AdaptiveRadixTree< V >::AdaptiveRadixTree ( AdaptiveRadixTree< V > && o)
noexcept

the items of other, which is left empty

◆ ~AdaptiveRadixTree()

template<class V>
ADS::AdaptiveRadixTree< V >::~AdaptiveRadixTree ( )

frees the memory of the structure

Member function documentation

◆ begin()

template<class V>
const_iterator ADS::AdaptiveRadixTree< V >::begin ( void ) const
nodiscard

the iterator on the first item

◆ cbegin()

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

the constant iterator on the first item

◆ cend()

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

the constant iterator past the last item

◆ clear()

template<class V>
void ADS::AdaptiveRadixTree< V >::clear ( void )

removes all the keys

◆ contains()

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

true if \( k \) is there

◆ empty()

template<class V>
bool ADS::AdaptiveRadixTree< V >::empty ( void ) const
nodiscard

true if there are no keys

◆ end()

template<class V>
const_iterator ADS::AdaptiveRadixTree< V >::end ( void ) const
nodiscard

the iterator past the last item

◆ find() [1/2]

template<class V>
V * ADS::AdaptiveRadixTree< V >::find ( std::string_view k)
nodiscard

the value of \( k \), to change in place, or nil

◆ find() [2/2]

template<class V>
const V * ADS::AdaptiveRadixTree< V >::find ( std::string_view k) const
nodiscard

the value of \( k \), or nil, by the search of lookup()

◆ forEach()

template<class V>
template<class F>
void ADS::AdaptiveRadixTree< V >::forEach ( F && f) const

f( key , value ) on each pair, by increasing keys

◆ forPrefix()

template<class V>
template<class F>
void ADS::AdaptiveRadixTree< V >::forPrefix ( std::string_view p,
F && f ) const

f( key , value ) on each pair whose key begins with \( p \), by increasing keys

◆ insert()

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

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}} \]

◆ keysWithPrefix()

template<class V>
std::vector< std::string > ADS::AdaptiveRadixTree< 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::AdaptiveRadixTree< V >::lookup ( std::string_view k) const
nodiscard

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}} \]

◆ operator=()

template<class V>
AdaptiveRadixTree & ADS::AdaptiveRadixTree< V >::operator= ( AdaptiveRadixTree< V > o)
noexcept

the assignment, by copy and swap

◆ remove()

template<class V>
bool ADS::AdaptiveRadixTree< V >::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

◆ size()

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

the number of keys

◆ swap()

template<class V>
void ADS::AdaptiveRadixTree< V >::swap ( AdaptiveRadixTree< V > & o)
noexcept

exchanges the contents with other in \( O( 1 ) \)


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