218# include <tclap/CmdLine.h>
225using namespace Aleph;
255 "Demonstrate BST split by position operation.\n"
256 "Creates a tree and splits it at a given position.",
259 TCLAP::ValueArg<int>
nArg(
"n",
"count",
260 "Number of elements",
264 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
265 "Random seed (0 = use time)",
266 false, 0,
"unsigned int");
269 TCLAP::ValueArg<int>
posArg(
"p",
"position",
270 "Split position (-1 = middle)",
276 int n =
nArg.getValue();
277 unsigned int t =
seedArg.getValue();
282 cerr <<
"Error: number of elements must be positive\n";
291 cout <<
"=== BST Split by Position Demo ===" <<
endl;
292 cout <<
"Elements: " << n <<
", Seed: " << t <<
endl <<
endl;
295 output.open(
"split-before-aux.Tree", ios::out);
296 output_1.open(
"split-1-aux.Tree", ios::out);
297 output_2.open(
"split-2-aux.Tree", ios::out);
301 cerr <<
"Error: cannot open output files" <<
endl;
309 cout <<
"Building ranked BST with " << n <<
" elements..." <<
endl;
310 for (
int i = 0; i < n; i++)
314 value =
static_cast<int>(1.0 * n *
rand() / (
RAND_MAX + 1.0));
356 cout <<
" Nodes: " << (
l ?
l->getCount() : 0)
372 cout <<
" Nodes: " << (r ? r->getCount() : 0)
377 cout <<
"Right subtree: empty" <<
endl;
388 cout <<
" - split-before-aux.Tree (original with split directive)" <<
endl;
389 cout <<
" - split-1-aux.Tree (left subtree)" <<
endl;
390 cout <<
" - split-2-aux.Tree (right subtree)" <<
endl;
392 catch (TCLAP::ArgException& e)
394 cerr <<
"Error: " << e.error() <<
" for arg " << e.argId() <<
endl;
Core header for the Aleph-w library.
WeightedDigraph::Node Node
Node for extended binary search tree.
static BinNodeXt *const NullPtr
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
Node * insert_by_key_xt(Node *&r, Node *p, Compare &cmp) noexcept
Insert a node in an extended binary search tree.
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended binary tree.
void split_pos_rec(Node *&r, const size_t i, Node *&ts, Node *&tg)
Split a extended binary tree according to a position.
bool check_bst(Node *p, const Compare &cmp=Compare())
Return true if p is a binary search tree.
void destroyRec(Node *&root) noexcept
Free recursively all the memory occupied by the tree root
Node * searchInBinTree(Node *root, const typename Node::key_type &key, const Compare &cmp=Compare()) noexcept
Search a key in a binary search tree.
size_t computeHeightRec(Node *root) noexcept
Compute recursively the height of root
Main namespace for Aleph-w library functions.
std::pair< std::string, std::string > split_pos(const std::string &str, const size_t pos)
Split a std::string at a fixed position.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Utility functions for binary tree operations.
Extended binary node with subtree count.
Generic unbalanced binary search tree.
Lazy and scalable dynamic array implementation.
void print_key(Node *p, int, int)
void print_key1(Node *p, int, int)
void print_key2(Node *p, int, int)