|
ADS
Algorithms and Data Structures
|
a DICTIONARY on a binary search tree balanced by partial rebuilding by the rule P More...
#include <ADS/tree/PartialRebuildingTree.h>
Classes | |
| struct | Shape |
| the shape of the tree, for PathIterator More... | |
Public types | |
| using | Key = K |
| the type of the keys | |
| using | Value = V |
| the type of the values | |
| using | value_type = std::pair< K , V > |
| the pairs ( key , value ) by value, which own their copies | |
| using | key_type = K |
| 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 | |
| using | reference = PairRef< const K & , const V & > |
| references, by value | |
| using | const_reference = reference |
| the same | |
| using | const_iterator = PathIterator< PartialRebuildingTree , Shape > |
| the constant iterator by increasing key, along the path from the root | |
| using | iterator = const_iterator |
| the constant iterator | |
Public member functions | |
| PartialRebuildingTree (std::uint64_t seed=1) | |
| the empty tree, its random choices (if any) drawn from the seed | |
| PartialRebuildingTree (const PartialRebuildingTree &)=delete | |
| no copy, since the nodes are linked by pointers | |
| PartialRebuildingTree & | operator= (const PartialRebuildingTree &)=delete |
| no copy, since the nodes are linked by pointers | |
| PartialRebuildingTree (PartialRebuildingTree &&other) noexcept | |
| the nodes of other, which is left empty | |
| ~PartialRebuildingTree () | |
| frees the nodes | |
| std::optional< V > | lookup (const K &k) const |
| the value of \( k \), or nothing, in \( O( h ) \) time | |
| void | insert (const K &k, const V &v) |
| associates \( v \) to \( k \), in \( O( \log n ) \) amortized time (for DynamiteTree, expected after insertions only, and \( O( h ) \) expected, \( h \) the height, after removals) | |
| void | remove (const K &k) |
| removes \( k \), if it is there, in \( O( \log n ) \) amortized time (for DynamiteTree, \( O( h ) \) expected, \( h \) the height), by the removal of a binary search tree and the rule of insert() on its path | |
| bool | contains (const K &k) const |
| true if \( k \) is there | |
| std::size_t | size (void) const |
| the number \( n \) of keys | |
| long | height (void) const |
| the height, \( -1 \) if empty, in \( O( n ) \) | |
| std::optional< std::pair< K, V > > | lowerBound (const K &k) const |
| the smallest key not smaller than \( k \) and its value, or nothing (the find(x) of an SSet of Morin) | |
| const K * | findKey (const K &k) const |
| the address of the key \( k \), nil if absent, in \( O( \log n ) \) time: the find( x ) of a USet of Morin [see DictionarySet]; valid until the key is removed | |
| const K * | lowerBoundKey (const K &k) const |
| the address of the smallest key not smaller than \( k \), nil if none, in \( O( \log n ) \) time: the find( x ) of an SSet of Morin [see DictionarySet]; valid until the key is removed | |
| template<class F> | |
| void | forEach (F &&f) const |
| f( k , v ) on the pairs by increasing keys | |
| std::size_t | rebuilds (void) const |
| the number of rebuilds so far | |
| std::size_t | rebuiltNodes (void) const |
| the nodes of all the rebuilds so far, the work they took | |
| const_iterator | begin (void) const |
| the iterator on the smallest key | |
| const_iterator | end (void) const |
| the iterator past the largest key | |
| const_iterator | cbegin (void) const |
| as begin() | |
| const_iterator | cend (void) const |
| as end() | |
a DICTIONARY on a binary search tree balanced by partial rebuilding by the rule P
| using ADS::PartialRebuildingTree< K, V, P >::const_iterator = PathIterator< PartialRebuildingTree , Shape > |
the constant iterator by increasing key, along the path from the root
| using ADS::PartialRebuildingTree< K, V, P >::const_reference = reference |
the same
| using ADS::PartialRebuildingTree< K, V, P >::difference_type = std::ptrdiff_t |
the type of the distances
| using ADS::PartialRebuildingTree< K, V, P >::iterator = const_iterator |
the constant iterator
| using ADS::PartialRebuildingTree< K, V, P >::Key = K |
the type of the keys
| using ADS::PartialRebuildingTree< K, V, P >::key_type = K |
the type of the keys
| using ADS::PartialRebuildingTree< K, V, P >::mapped_type = V |
the type of the values
| using ADS::PartialRebuildingTree< K, V, P >::reference = PairRef< const K & , const V & > |
references, by value
| using ADS::PartialRebuildingTree< K, V, P >::size_type = std::size_t |
the type of the sizes
| using ADS::PartialRebuildingTree< K, V, P >::Value = V |
the type of the values
| using ADS::PartialRebuildingTree< K, V, P >::value_type = std::pair< K , V > |
the pairs ( key , value ) by value, which own their copies
|
inlineexplicit |
the empty tree, its random choices (if any) drawn from the seed
|
delete |
no copy, since the nodes are linked by pointers
|
noexcept |
the nodes of other, which is left empty
| ADS::PartialRebuildingTree< K, V, P >::~PartialRebuildingTree | ( | ) |
frees the nodes
|
inlinenodiscard |
the iterator on the smallest key
|
inlinenodiscard |
as begin()
|
inlinenodiscard |
as end()
|
nodiscard |
true if \( k \) is there
|
inlinenodiscard |
the iterator past the largest key
|
nodiscard |
the address of the key \( k \), nil if absent, in \( O( \log n ) \) time: the find( x ) of a USet of Morin [see DictionarySet]; valid until the key is removed
| void ADS::PartialRebuildingTree< K, V, P >::forEach | ( | F && | f | ) | const |
f( k , v ) on the pairs by increasing keys
|
nodiscard |
the height, \( -1 \) if empty, in \( O( n ) \)
| void ADS::PartialRebuildingTree< K, V, P >::insert | ( | const K & | k, |
| const V & | v ) |
associates \( v \) to \( k \), in \( O( \log n ) \) amortized time (for DynamiteTree, expected after insertions only, and \( O( h ) \) expected, \( h \) the height, after removals)
In pseudocode (exercises 8.8 to 8.10 of Morin), \( P \) the path from the root to the new leaf:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr 2 & \quad \text{the insertion of a binary search tree, along } P \cr 3 & \quad \textbf{foreach}\ u \in P\ \textbf{do}\ s( u ) \gets s( u ) + 1 \cr 4 & \quad w \gets \text{the first node of } P \text{ selected by the} \text{ rule} \cr 5 & \quad \textbf{if}\ w \ne \textbf{nil}\ \textbf{then} \ \mathrm{rebuild}( w ) \end{array}} \]
where the rule selects \( u \) with a child of size above \( \frac23 s( u ) \) (WEIGHT), \( u \) whose timer, decremented, is 0 (COUNTDOWN), \( u \) with probability \( 1 / s( u ) \) (DYNAMITE)
|
nodiscard |
the value of \( k \), or nothing, in \( O( h ) \) time
|
nodiscard |
the smallest key not smaller than \( k \) and its value, or nothing (the find(x) of an SSet of Morin)
|
nodiscard |
the address of the smallest key not smaller than \( k \), nil if none, in \( O( \log n ) \) time: the find( x ) of an SSet of Morin [see DictionarySet]; valid until the key is removed
|
delete |
no copy, since the nodes are linked by pointers
|
inlinenodiscard |
the number of rebuilds so far
|
inlinenodiscard |
the nodes of all the rebuilds so far, the work they took
| void ADS::PartialRebuildingTree< K, V, P >::remove | ( | const K & | k | ) |
removes \( k \), if it is there, in \( O( \log n ) \) amortized time (for DynamiteTree, \( O( h ) \) expected, \( h \) the height), by the removal of a binary search tree and the rule of insert() on its path
|
inlinenodiscard |
the number \( n \) of keys