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

a trie of strings with the bitmaps of the children, the list of the strings and the smallest and largest string below each node More...

#include <ADS/dictionary/BitmapTrie.h>

Classes

class  const_iterator
 the bidirectional iterator along the list More...

Public types

using Key = std::string
 the type of the keys
using Item = std::string
 the items of the SSet, the strings
using Value = V
 the type of the values
using value_type = typename const_iterator::value_type
 the type of the items, for the standard library
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 = typename const_iterator::reference
 a pair of references, by value
using const_reference = reference
 a pair of references, by value
using iterator = const_iterator
 the iterator on the items

Public member functions

 BitmapTrie (void)
 the empty trie
 BitmapTrie (BitmapTrie &&o)
 the trie of o, which is left empty
BitmapTrie & operator= (BitmapTrie &&o) noexcept
 the trie of o, which gets the strings of this one
 BitmapTrie (const BitmapTrie &)=delete
BitmapTrie & operator= (const BitmapTrie &)=delete
 ~BitmapTrie ()
 frees the nodes and the strings
const std::string * lowerBound (std::string_view s) const
 the smallest string \( \ge s \), nil if none (the find( s ) of the SSet of Morin's book), in \( O( |s| ) \) time
const std::string * find (std::string_view s) const
 the string \( s \), nil if it is not there, in \( O( |s| ) \) time
std::optional< V > lookup (std::string_view s) const
 the value of \( s \), or nothing, in \( O( |s| ) \) time
bool contains (std::string_view s) const
 true if \( s \) is there, in \( O( |s| ) \) time
bool insert (std::string_view s, const V &v=V())
 associates \( v \) to \( s \); true if \( s \) was not there, in \( O( |s| ) \) time
bool remove (std::string_view s)
 removes \( s \); true if it was there, in \( O( |s| ) \) time
std::size_t size (void) const
 the number of strings
bool empty (void) const
 true if there are no strings
std::size_t nodes (void) const
 the number of nodes, the root included
const_iterator begin (void) const
 the iterator on the smallest string
const_iterator end (void) const
 the iterator past the largest string
const_iterator cbegin (void) const
 as begin()
const_iterator cend (void) const
 as end()
const_iterator seek (std::string_view s) const
 the iterator on the smallest string \( \ge s \), end() if none

Detailed description

template<class V = std::monostate>
class ADS::BitmapTrie< V >

a trie of strings with the bitmaps of the children, the list of the strings and the smallest and largest string below each node

Member typedef documentation

◆ const_reference

template<class V = std::monostate>
using ADS::BitmapTrie< V >::const_reference = reference

a pair of references, by value

◆ difference_type

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

the type of the distances between two iterators

◆ Item

template<class V = std::monostate>
using ADS::BitmapTrie< V >::Item = std::string

the items of the SSet, the strings

◆ iterator

template<class V = std::monostate>
using ADS::BitmapTrie< V >::iterator = const_iterator

the iterator on the items

◆ Key

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

the type of the keys

◆ reference

template<class V = std::monostate>
using ADS::BitmapTrie< V >::reference = typename const_iterator::reference

a pair of references, by value

◆ size_type

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

the type of the sizes

◆ Value

template<class V = std::monostate>
using ADS::BitmapTrie< V >::Value = V

the type of the values

◆ value_type

template<class V = std::monostate>
using ADS::BitmapTrie< V >::value_type = typename const_iterator::value_type

the type of the items, for the standard library

Constructor and destructor documentation

◆ BitmapTrie() [1/3]

template<class V = std::monostate>
ADS::BitmapTrie< V >::BitmapTrie ( void )

the empty trie

◆ BitmapTrie() [2/3]

template<class V = std::monostate>
ADS::BitmapTrie< V >::BitmapTrie ( BitmapTrie< V > && o)

the trie of o, which is left empty

◆ BitmapTrie() [3/3]

template<class V = std::monostate>
ADS::BitmapTrie< V >::BitmapTrie ( const BitmapTrie< V > & )
delete

◆ ~BitmapTrie()

template<class V = std::monostate>
ADS::BitmapTrie< V >::~BitmapTrie ( )

frees the nodes and the strings

Member function documentation

◆ begin()

template<class V = std::monostate>
const_iterator ADS::BitmapTrie< V >::begin ( void ) const
inlinenodiscard

the iterator on the smallest string

◆ cbegin()

template<class V = std::monostate>
const_iterator ADS::BitmapTrie< V >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<class V = std::monostate>
const_iterator ADS::BitmapTrie< V >::cend ( void ) const
inlinenodiscard

as end()

◆ contains()

template<class V = std::monostate>
bool ADS::BitmapTrie< V >::contains ( std::string_view s) const
nodiscard

true if \( s \) is there, in \( O( |s| ) \) time

◆ empty()

template<class V = std::monostate>
bool ADS::BitmapTrie< V >::empty ( void ) const
inlinenodiscard

true if there are no strings

◆ end()

template<class V = std::monostate>
const_iterator ADS::BitmapTrie< V >::end ( void ) const
inlinenodiscard

the iterator past the largest string

◆ find()

template<class V = std::monostate>
const std::string * ADS::BitmapTrie< V >::find ( std::string_view s) const
nodiscard

the string \( s \), nil if it is not there, in \( O( |s| ) \) time

◆ insert()

template<class V = std::monostate>
bool ADS::BitmapTrie< V >::insert ( std::string_view s,
const V & v = V() )

associates \( v \) to \( s \); true if \( s \) was not there, in \( O( |s| ) \) time

In pseudocode (exercise 13.3 of Morin's book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( s , v ) \cr 2 & \quad \textbf{if}\ s \text{ is there}\ \textbf{then}\ \text{give it } \text{the value } v;\ \textbf{return false} \cr 3 & \quad \text{link } s \text{ before the string of } \mathrm{lowerBound}( s ) \text{, add the missing nodes of its path} \cr 4 & \quad \textbf{for}\ i \gets |s|\ \textbf{downto}\ 0\ \textbf{do} \quad \triangleright\ u \text{ the node of depth } i \cr 5 & \qquad \textbf{if}\ \text{nothing of } u \text{ precedes the path } \text{of } s \text{ and } s \text{ is the } \mathit{min} \text{ of } \text{the next node}\ \textbf{then}\ u.\mathit{min} \gets s \cr 6 & \qquad \textbf{if}\ \text{nothing of } u \text{ follows the path } \text{of } s \text{ and } s \text{ is the } \mathit{max} \text{ of } \text{the next node}\ \textbf{then}\ u.\mathit{max} \gets s \cr 7 & \quad \textbf{return true} \end{array}} \]

Postcondition
\( s \) is there

◆ lookup()

template<class V = std::monostate>
std::optional< V > ADS::BitmapTrie< V >::lookup ( std::string_view s) const
nodiscard

the value of \( s \), or nothing, in \( O( |s| ) \) time

◆ lowerBound()

template<class V = std::monostate>
const std::string * ADS::BitmapTrie< V >::lowerBound ( std::string_view s) const
nodiscard

the smallest string \( \ge s \), nil if none (the find( s ) of the SSet of Morin's book), in \( O( |s| ) \) time

In pseudocode (exercise 13.3 of Morin's book), \( u.\mathit{min} \) and \( u.\mathit{max} \) the smallest and the largest string below \( u \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lowerBound}( s ) \cr 2 & \quad u \gets \mathit{root} \cr 3 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ |s| - 1\ \textbf{do} \cr 4 & \qquad \textbf{if}\ u \text{ has a child of } s_i\ \textbf{then} \ u \gets \text{that child};\ \textbf{continue} \cr 5 & \qquad \textbf{if}\ u \text{ has a child of a byte} > s_i \ \textbf{then return}\ \text{the } \mathit{min} \text{ of the } \text{first one} \cr 6 & \qquad \textbf{return}\ u.\mathit{max}.\mathit{next} \cr 7 & \quad \textbf{return}\ u.\mathit{min} \end{array}} \]

◆ nodes()

template<class V = std::monostate>
std::size_t ADS::BitmapTrie< V >::nodes ( void ) const
inlinenodiscard

the number of nodes, the root included

◆ operator=() [1/2]

template<class V = std::monostate>
BitmapTrie & ADS::BitmapTrie< V >::operator= ( BitmapTrie< V > && o)
noexcept

the trie of o, which gets the strings of this one

◆ operator=() [2/2]

template<class V = std::monostate>
BitmapTrie & ADS::BitmapTrie< V >::operator= ( const BitmapTrie< V > & )
delete

◆ remove()

template<class V = std::monostate>
bool ADS::BitmapTrie< V >::remove ( std::string_view s)

removes \( s \); true if it was there, in \( O( |s| ) \) time

In pseudocode (exercise 13.3 of Morin's book), \( \ell \) the item of \( s \) in the list:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{remove}( s ) \cr 2 & \quad \textbf{if}\ s \text{ is not there}\ \textbf{then return false} \cr 3 & \quad \text{unlink } \ell;\ \text{remove the nodes of the path of } s \text{ left with no string below} \cr 4 & \quad \textbf{foreach}\ \text{node } u \text{ left on the path} \ \textbf{do} \cr 5 & \qquad \textbf{if}\ u.\mathit{min} = \ell\ \textbf{then} \ u.\mathit{min} \gets \ell.\mathit{next} \cr 6 & \qquad \textbf{if}\ u.\mathit{max} = \ell\ \textbf{then} \ u.\mathit{max} \gets \ell.\mathit{prev} \cr 7 & \quad \textbf{return true} \end{array}} \]

Postcondition
\( s \) is not there

◆ seek()

template<class V = std::monostate>
const_iterator ADS::BitmapTrie< V >::seek ( std::string_view s) const
nodiscard

the iterator on the smallest string \( \ge s \), end() if none

◆ size()

template<class V = std::monostate>
std::size_t ADS::BitmapTrie< V >::size ( void ) const
inlinenodiscard

the number of strings


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