|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
DynSetTree (dynamic set) with multiple BST backends in Aleph-w. More...
#include <iostream>#include <iomanip>#include <chrono>#include <vector>#include <algorithm>#include <tclap/CmdLine.h>#include <tpl_dynSetTree.H>Go to the source code of this file.
Classes | |
| struct | TimingResult |
Typedefs | |
| using | AvlSet = DynSetTree< int, Avl_Tree > |
| using | RbSet = DynSetTree< int, Rb_Tree > |
| using | SplaySet = DynSetTree< int, Splay_Tree > |
| using | TreapSet = DynSetTree< int, Treap > |
| using | RandSet = DynSetTree< int, Rand_Tree > |
| using | AvlRkSet = DynSetTree< int, Avl_Tree_Rk > |
| using | TreapRkSet = DynSetTree< int, Treap_Rk > |
Functions | |
| template<typename Set > | |
| TimingResult | benchmark_set (const string &name, const vector< int > &data, bool verbose) |
| void | demonstrate_basic_operations () |
| void | demonstrate_tree_types () |
| void | demonstrate_ranked_operations () |
| void | demonstrate_functional_features () |
| void | run_performance_comparison (size_t n, unsigned int seed, bool verbose) |
| int | main (int argc, char *argv[]) |
DynSetTree (dynamic set) with multiple BST backends in Aleph-w.
This example demonstrates DynSetTree, a uniform set interface whose underlying ordered structure is selected via template parameter.
It highlights:
intDynSetTree<int, TreeBackend>Aleph::less<int>Standard (non-ranked) backends:
Avl_Tree, Rb_Tree, Splay_Tree, Treap, Rand_TreeRanked backends used by this file:
Avl_Tree_Rk, Treap_RkNote: Aleph-w also provides other ranked variants (e.g. Rb_Tree_Rk, Splay_Tree_Rk), but this example does not instantiate them.
This example uses TCLAP. Options:
--count / -n <size_t>: number of elements used for the performance test (default: 100000).--seed / -s <unsigned>: RNG seed (0 means use time(); default: 0).--all / -a: run all demonstrations (not only the performance benchmark).--verbose / -v: print extra per-tree statistics.--help: show help.Expected/typical per-operation complexities by backend:
O(log n) worst-caseO(log n) amortizedO(log n) expectedThe benchmark section measures these costs empirically for one workload (random keys).
tpl_dynSetTree.H (DynSetTree)timeAllTree.C (deeper tree micro-benchmark)tpl_avl.H, tpl_rb_tree.H, tpl_splay_tree.H, tpl_treap.HDefinition in file dynset_trees.C.
| using AvlRkSet = DynSetTree<int, Avl_Tree_Rk> |
Definition at line 147 of file dynset_trees.C.
| using AvlSet = DynSetTree<int, Avl_Tree> |
Definition at line 139 of file dynset_trees.C.
| using RandSet = DynSetTree<int, Rand_Tree> |
Definition at line 143 of file dynset_trees.C.
| using RbSet = DynSetTree<int, Rb_Tree> |
Definition at line 140 of file dynset_trees.C.
| using SplaySet = DynSetTree<int, Splay_Tree> |
Definition at line 141 of file dynset_trees.C.
| using TreapRkSet = DynSetTree<int, Treap_Rk> |
Definition at line 148 of file dynset_trees.C.
| using TreapSet = DynSetTree<int, Treap> |
Definition at line 142 of file dynset_trees.C.
| TimingResult benchmark_set | ( | const string & | name, |
| const vector< int > & | data, | ||
| bool | verbose | ||
| ) |
Definition at line 168 of file dynset_trees.C.
References Aleph::computeHeightRec(), TimingResult::height, TimingResult::insert_ms, TimingResult::internal_path_length, Aleph::internal_path_length(), Aleph::maps(), TimingResult::name, TimingResult::remove_ms, TimingResult::search_ms, and Aleph::verbose.
| void demonstrate_basic_operations | ( | ) |
Definition at line 224 of file dynset_trees.C.
References FunctionalMethods< Container, T >::for_each(), Aleph::DynList< T >::insert(), Aleph::maps(), Aleph::DynList< T >::remove(), and Aleph::HTList::size().
Referenced by main().
| void demonstrate_functional_features | ( | ) |
Definition at line 387 of file dynset_trees.C.
References FunctionalMethods< Container, T >::all(), FunctionalMethods< Container, T >::exists(), FunctionalMethods< Container, T >::filter(), FunctionalMethods< Container, T >::for_each(), Aleph::DynSetTree< Key, Tree, Compare >::insert(), Aleph::maps(), and Aleph::sum().
Referenced by main().
| void demonstrate_ranked_operations | ( | ) |
Definition at line 316 of file dynset_trees.C.
References FunctionalMethods< Container, T >::for_each(), Aleph::DynList< T >::insert(), Aleph::maps(), and Aleph::HTList::size().
Referenced by main().
| void demonstrate_tree_types | ( | ) |
Definition at line 269 of file dynset_trees.C.
References Aleph::computeHeightRec(), Aleph::DynSetTree< Key, Tree, Compare >::get_root_node(), Aleph::DynSetTree< Key, Tree, Compare >::insert(), Aleph::DynList< T >::insert(), Aleph::maps(), and Aleph::DynSetTree< Key, Tree, Compare >::search().
Referenced by main().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 513 of file dynset_trees.C.
References demonstrate_basic_operations(), demonstrate_functional_features(), demonstrate_ranked_operations(), demonstrate_tree_types(), Aleph::maps(), run_performance_comparison(), and Aleph::verbose.
| void run_performance_comparison | ( | size_t | n, |
| unsigned int | seed, | ||
| bool | verbose | ||
| ) |
Definition at line 428 of file dynset_trees.C.
References log2(), Aleph::maps(), Aleph::HTList::size(), Aleph::sort(), Aleph::swap(), Aleph::unique(), and Aleph::verbose.
Referenced by main().