a DICTIONARY on a scapegoat tree of height at most \( \log_b q \), whose nodes keep the size of their subtree if StoredSizes
More...
|
| enum class | Sizes { RECOMPUTE
, REUSE
} |
| | how the sizes are found when they are not stored More...
|
| enum class | Scapegoats { HEIGHT
, WEIGHT
} |
| | which ancestor is the scapegoat More...
|
| enum class | Rebuilds { ARRAY
, LIST
} |
| | how a subtree is rebuilt More...
|
| 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< ScapegoatTree , Shape > |
| | the constant iterator by increasing key, along the path from the root
|
| using | iterator = const_iterator |
| | the constant iterator
|
|
| | ScapegoatTree (double b=1.5, Sizes sizes=Sizes::REUSE, Rebuilds rebuilds=Rebuilds::ARRAY, Scapegoats scapegoats=Scapegoats::HEIGHT) |
| | the empty tree of height at most \( \log_b q \)
|
| | ScapegoatTree (const ScapegoatTree &)=delete |
| | no copy, since the nodes are linked by pointers
|
| ScapegoatTree & | operator= (const ScapegoatTree &)=delete |
| | no copy, since the nodes are linked by pointers
|
| | ScapegoatTree (ScapegoatTree &&other) noexcept |
| | the nodes of other, which is left empty
|
| | ~ScapegoatTree () |
| | frees the nodes
|
| std::optional< V > | lookup (const K &k) const |
| | the value of \( k \), or nothing, in \( O( \log n ) \) time
|
| void | insert (const K &k, const V &v) |
| | associates \( v \) to \( k \), in \( O( \log n ) \) amortized time
|
| void | remove (const K &k) |
| | removes \( k \), if it is there, in \( O( \log n ) \) amortized time: the removal of a binary search tree, then the whole tree rebuilt if \( q > 2 n \), and \( q \gets n \)
|
| 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()
|
template<std::totally_ordered K, class V, bool StoredSizes = false>
class ADS::ScapegoatTree< K, V, StoredSizes >
a DICTIONARY on a scapegoat tree of height at most \( \log_b q \), whose nodes keep the size of their subtree if StoredSizes
template<std::totally_ordered K, class V, bool StoredSizes = false>
associates \( v \) to \( k \), in \( O( \log n ) \) amortized time
In pseudocode (section 8.1 of Morin), \( s \) the sizes and \( P \) the path of the descent:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr
2 & \quad u \gets \text{a new leaf of } ( k , v ) \text{ at the depth }
d \text{, after } P;\ n \gets n + 1;\ q \gets q + 1 \cr
3 & \quad \textbf{if}\ d > \log_b q\ \textbf{then} \cr
4 & \qquad w \gets u.\mathit{parent} \cr
5 & \qquad \textbf{while}\ b^{d - \mathrm{depth}( w )} \le s( w )
\ \textbf{do}\ u \gets w;\ w \gets w.\mathit{parent} \cr
& \qquad\quad \triangleright\ \text{for }\mathtt{WEIGHT}\text{: }
\textbf{while}\ b \cdot s( u ) \le s( w ) \cr
6 & \qquad \mathrm{rebuild}( w )
\end{array}}
\]
- Postcondition
- \( k \) has the value \( v \)
template<std::totally_ordered K, class V, bool StoredSizes = false>
removes \( k \), if it is there, in \( O( \log n ) \) amortized time: the removal of a binary search tree, then the whole tree rebuilt if \( q > 2 n \), and \( q \gets n \)
In pseudocode (section 8.1 of Morin):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{remove}( k ) \cr
2 & \quad \textbf{if}\ k \text{ is not there}\ \textbf{then return}
\cr
3 & \quad \text{the removal of a binary search tree};\ n \gets n - 1
\cr
4 & \quad \textbf{if}\ 2 n < q\ \textbf{then}\ \mathrm{rebuild}(
\mathit{root} );\ q \gets n
\end{array}}
\]
- Postcondition
- \( k \) is not there