|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Generates tree structure files for visualization and analysis. More...
#include <iostream>#include <fstream>#include <cstdlib>#include <ctime>#include <vector>#include <set>#include <tclap/CmdLine.h>#include <aleph.H>#include <tpl_avl.H>#include <tpl_rb_tree.H>#include <tpl_splay_tree.H>#include <tpl_treap.H>#include <tpl_rand_tree.H>#include <tpl_binTree.H>#include <tpl_binNodeUtils.H>Go to the source code of this file.
Functions | |
| vector< int > | generate_random_values (size_t n, unsigned int seed) |
| static void | avl_print_key (Avl_Tree< int >::Node *p, int, int) |
| void | write_avl (const vector< int > &values, const string &prefix) |
| static void | rb_print_key (Rb_Tree< int >::Node *p, int, int) |
| static void | rb_write_colors (Rb_Tree< int >::Node *p, int, int) |
| void | write_rb (const vector< int > &values, const string &prefix) |
| static void | splay_print_key (Splay_Tree< int >::Node *p, int, int) |
| void | write_splay (const vector< int > &values, const string &prefix) |
| static void | treap_print_key (Treap< int >::Node *p, int, int) |
| void | write_treap (const vector< int > &values, const string &prefix) |
| static void | rand_print_key (Rand_Tree< int >::Node *p, int, int) |
| void | write_rand (const vector< int > &values, const string &prefix) |
| static void | bin_print_key (BinTree< int >::Node *p, int, int) |
| void | write_bin (const vector< int > &values, const string &prefix) |
| int | main (int argc, char *argv[]) |
Variables | |
| static ofstream * | current_output = nullptr |
| static int | rb_pos = 0 |
Generates tree structure files for visualization and analysis.
This utility program creates .Tree files containing binary search tree structures in preorder traversal format. These files are designed for visualization tools like btreepic or for algorithm testing and analysis. This tool is essential for understanding how different BST implementations structure the same data differently.
This tool is useful for:
| Type | Description | Balance Strategy | Best For |
|---|---|---|---|
| AVL | Strictly balanced | Height difference ≤ 1 | Read-heavy |
| Red-Black | Relaxed balance | No path > 2× shortest | General purpose |
| Splay | Self-adjusting | Moves accessed nodes to root | Temporal locality |
| Treap | Randomized | Heap priorities for balance | Simple, average case |
| Rand | Randomized BST | Random insertion order | Alternative random |
| Binary | Unbalanced | No balancing | Baseline, educational |
Each .Tree file contains:
btreepic visualization toolFiles are named: @p prefix + @p tree_type + ".Tree"
test_avl.Tree (use -o test_), rb.Tree (default prefix), mytree_splay.Tree (use -o mytree_)The .Tree format includes:
Generate same data with different tree types to compare:
| Parameter | Short | Description | Default |
|---|---|---|---|
--count | -n | Number of nodes to insert | 30 |
--seed | -s | Random seed for reproducibility | Time-based |
--type | -t | Tree type (avl, rb, splay, treap, rand, bin, all) | all |
--output | -o | Output file prefix (concatenated literally; use a trailing _ if you want a separator) | empty |
Generated .Tree files can be visualized:
The visualization generates LaTeX files suitable for:
Definition in file write_tree.C.
| vector< int > generate_random_values | ( | size_t | n, |
| unsigned int | seed | ||
| ) |
Definition at line 247 of file write_tree.C.
References StlAlephIterator< SetName >::end(), Aleph::DynList< T >::insert(), and Aleph::maps().
Referenced by main().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 545 of file write_tree.C.
References generate_random_values(), Aleph::maps(), Aleph::prefix(), Aleph::HTList::size(), write_avl(), write_bin(), write_rand(), write_rb(), write_splay(), and write_treap().
Definition at line 326 of file write_tree.C.
References COLOR, current_output, rb_pos, and RED.
Referenced by write_rb().
|
static |
Definition at line 377 of file write_tree.C.
References current_output.
Referenced by write_splay().
Definition at line 419 of file write_tree.C.
References current_output.
Referenced by write_treap().
| void write_avl | ( | const vector< int > & | values, |
| const string & | prefix | ||
| ) |
Definition at line 283 of file write_tree.C.
References avl_print_key(), Aleph::computeHeightRec(), Aleph::count(), current_output, Aleph::destroyRec(), Aleph::Gen_Avl_Tree< NodeType, Key, Compare >::getRoot(), Aleph::Gen_Avl_Tree< NodeType, Key, Compare >::insert(), Aleph::maps(), output, Aleph::prefix(), Aleph::preOrderRec(), and Aleph::Gen_Avl_Tree< NodeType, Key, Compare >::search().
Referenced by main().
| void write_bin | ( | const vector< int > & | values, |
| const string & | prefix | ||
| ) |
Definition at line 508 of file write_tree.C.
References bin_print_key(), Aleph::computeHeightRec(), Aleph::count(), current_output, Aleph::destroyRec(), Aleph::GenBinTree< NodeType, Key, Compare >::getRoot(), Aleph::GenBinTree< NodeType, Key, Compare >::insert(), Aleph::maps(), output, Aleph::prefix(), Aleph::preOrderRec(), and Aleph::GenBinTree< NodeType, Key, Compare >::search().
Referenced by main().
| void write_rand | ( | const vector< int > & | values, |
| const string & | prefix | ||
| ) |
Definition at line 466 of file write_tree.C.
References Aleph::computeHeightRec(), current_output, Aleph::destroyRec(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::getRoot(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::insert(), Aleph::maps(), output, Aleph::prefix(), Aleph::preOrderRec(), rand_print_key(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::search(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::size().
Referenced by main().
| void write_rb | ( | const vector< int > & | values, |
| const string & | prefix | ||
| ) |
Definition at line 333 of file write_tree.C.
References Aleph::computeHeightRec(), Aleph::count(), current_output, Aleph::destroyRec(), Aleph::Gen_Rb_Tree< NodeType, Key, Compare >::getRoot(), Aleph::inOrderRec(), Aleph::Gen_Rb_Tree< NodeType, Key, Compare >::insert(), Aleph::maps(), output, Aleph::prefix(), Aleph::preOrderRec(), rb_pos, rb_print_key(), rb_write_colors(), and Aleph::Gen_Rb_Tree< NodeType, Key, Compare >::search().
Referenced by main().
| void write_splay | ( | const vector< int > & | values, |
| const string & | prefix | ||
| ) |
Definition at line 382 of file write_tree.C.
References Aleph::computeHeightRec(), Aleph::count(), current_output, Aleph::destroyRec(), GenTdSplayTree< NodeType, Key, Compare >::getRoot(), GenTdSplayTree< NodeType, Key, Compare >::insert(), Aleph::maps(), output, Aleph::prefix(), Aleph::preOrderRec(), GenTdSplayTree< NodeType, Key, Compare >::search(), and splay_print_key().
Referenced by main().
| void write_treap | ( | const vector< int > & | values, |
| const string & | prefix | ||
| ) |
Definition at line 424 of file write_tree.C.
References Aleph::computeHeightRec(), Aleph::count(), current_output, Aleph::destroyRec(), Aleph::Gen_Treap< NodeType, Key, Compare >::getRoot(), Aleph::Gen_Treap< NodeType, Key, Compare >::insert(), Aleph::maps(), output, Aleph::prefix(), Aleph::preOrderRec(), Aleph::Gen_Treap< NodeType, Key, Compare >::search(), and treap_print_key().
Referenced by main().
|
static |
Definition at line 272 of file write_tree.C.
Referenced by avl_print_key(), bin_print_key(), rand_print_key(), rb_print_key(), rb_write_colors(), splay_print_key(), treap_print_key(), write_avl(), write_bin(), write_rand(), write_rb(), write_splay(), and write_treap().
|
static |
Definition at line 325 of file write_tree.C.
Referenced by rb_write_colors(), and write_rb().