|
ADS
Algorithms and Data Structures
|
Three trees balanced by partial rebuilding, from exercises 8.8 to 8.10 of Morin, beyond the book: binary search trees whose insertions and removals are those of the plain tree, followed by the rebuilding of the subtree of the highest node of the path that a rule selects into a perfectly balanced one [see ScapegoatTree.h for the rebuild]. More...
#include "ADS/Contract.h"#include "ADS/Iterators.h"#include "ADS/dictionary/RandomHashing.h"#include "ADS/numeric/RandomGenerators.h"#include "ADS/tree/BinaryTreeAlgorithms.h"#include "ADS/tree/ScapegoatTree.h"#include <algorithm>#include <concepts>#include <cstddef>#include <cstdint>#include <optional>#include <type_traits>#include <utility>#include <vector>#include "ADS/tree/impl/PartialRebuildingTree.tpp"Go to the source code of this file.
Classes | |
| class | ADS::PartialRebuildingTree< K, V, P > |
| a DICTIONARY on a binary search tree balanced by partial rebuilding by the rule P More... | |
| struct | ADS::PartialRebuildingTree< K, V, P >::Shape |
| the shape of the tree, for PathIterator More... | |
Namespaces | |
| namespace | ADS |
Typedefs | |
| template<std::totally_ordered K, class V> | |
| using | ADS::WeightRebuildTree |
| the tree of exercise 8.8 of Morin, balanced by weight by rebuilds | |
| template<std::totally_ordered K, class V> | |
| using | ADS::CountdownTree |
| the CountdownTree of exercise 8.9 of Morin | |
| template<std::totally_ordered K, class V> | |
| using | ADS::DynamiteTree = PartialRebuildingTree< K , V , RebuildPolicy::DYNAMITE > |
| the DynamiteTree of exercise 8.10 of Morin | |
Enumerations | |
| enum class | ADS::RebuildPolicy { ADS::RebuildPolicy::WEIGHT , ADS::RebuildPolicy::COUNTDOWN , ADS::RebuildPolicy::DYNAMITE } |
| the rules that select the subtree to rebuild More... | |
Three trees balanced by partial rebuilding, from exercises 8.8 to 8.10 of Morin, beyond the book: binary search trees whose insertions and removals are those of the plain tree, followed by the rebuilding of the subtree of the highest node of the path that a rule selects into a perfectly balanced one [see ScapegoatTree.h for the rebuild].
Each node keeps the size of its subtree, updated along the path. They are DICTIONARY [see ADT.h] with the find(x) of an SSet (lowerBound()), and the policy is the parameter of PartialRebuildingTree:
The analyses are in Trees of partial rebuilding. The random choices of DynamiteTree come from SplitMix64 [see RandomHashing.h] by uniformBelow() [see RandomGenerators.h].
Morin gives no code for them: the benchmarks compare them with ScapegoatTree, which pays its rebuilds by \( q \) and needs no field in the nodes, while these keep a size (and a timer) in each node.
The contracts [see Contract.h]: insert() ensures that the key is there and remove() that it is not; the invariant, an \( O( n ) \) check at the level 3, is the order of the keys, the sizes and, for WeightRebuildTree, the balance of the weights. The operations are defined in PartialRebuildingTree.tpp.