|
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>#include <cstdlib>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 149 of file dynset_trees.C.
| using AvlSet = DynSetTree<int, Avl_Tree> |
Definition at line 141 of file dynset_trees.C.
| using RandSet = DynSetTree<int, Rand_Tree> |
Definition at line 145 of file dynset_trees.C.
| using RbSet = DynSetTree<int, Rb_Tree> |
Definition at line 142 of file dynset_trees.C.
| using SplaySet = DynSetTree<int, Splay_Tree> |
Definition at line 143 of file dynset_trees.C.
| using TreapRkSet = DynSetTree<int, Treap_Rk> |
Definition at line 150 of file dynset_trees.C.
| using TreapSet = DynSetTree<int, Treap> |
Definition at line 144 of file dynset_trees.C.
| TimingResult benchmark_set | ( | const string & | name, |
| const vector< int > & | data, | ||
| bool | verbose | ||
| ) |
Definition at line 170 of file dynset_trees.C.
References Aleph::computeHeightRec(), Aleph::divide_and_conquer_partition_dp(), TimingResult::height, TimingResult::insert_ms, TimingResult::internal_path_length, Aleph::internal_path_length(), TimingResult::name, TimingResult::remove_ms, TimingResult::search_ms, and Aleph::verbose.
| void demonstrate_basic_operations | ( | ) |
Definition at line 226 of file dynset_trees.C.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::DynSetTree< Key, Tree, Compare >::insert().
Referenced by main().
| void demonstrate_functional_features | ( | ) |
Definition at line 389 of file dynset_trees.C.
References FunctionalMethods< Container, T >::all(), Aleph::divide_and_conquer_partition_dp(), FunctionalMethods< Container, T >::exists(), FunctionalMethods< Container, T >::filter(), FunctionalMethods< Container, T >::for_each(), Aleph::DynSetTree< Key, Tree, Compare >::insert(), and Aleph::sum().
Referenced by main().
| void demonstrate_ranked_operations | ( | ) |
Definition at line 318 of file dynset_trees.C.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::DynSetTree< Key, Tree, Compare >::insert().
Referenced by main().
| void demonstrate_tree_types | ( | ) |
Definition at line 271 of file dynset_trees.C.
References Aleph::computeHeightRec(), Aleph::divide_and_conquer_partition_dp(), Aleph::DynSetTree< Key, Tree, Compare >::get_root_node(), Aleph::DynSetTree< Key, Tree, Compare >::insert(), and Aleph::DynSetTree< Key, Tree, Compare >::search().
Referenced by main().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 515 of file dynset_trees.C.
References cmd, demonstrate_basic_operations(), demonstrate_functional_features(), demonstrate_ranked_operations(), demonstrate_tree_types(), Aleph::divide_and_conquer_partition_dp(), run_performance_comparison(), seed, and Aleph::verbose.
| void run_performance_comparison | ( | size_t | n, |
| unsigned int | seed, | ||
| bool | verbose | ||
| ) |
Definition at line 430 of file dynset_trees.C.
References Aleph::divide_and_conquer_partition_dp(), log2(), r, seed, Aleph::sort(), Aleph::swap(), Aleph::unique(), and Aleph::verbose.
Referenced by main().