50 cout <<
"(" << node->get_key() <<
"," << node->get_data() <<
")";
55 template <
typename ,
class >
59 unsigned long max = 100*n;
64 for (i = 0; i < n; i++)
70 cout <<
"Reading test ... " << endl;
74 for (i = 0; i < n; i++)
90 cout <<
"Writing test ... " << endl;
92 for (i = 0; i < n; i++)
96 cout <<
"(" << val <<
"," << i <<
")";
103 cout <<
"The height is " << tree.
height() << endl;
105 unsigned int insCount = tree.
size();
106 cout << insCount <<
" Items inserted" << endl;
108 for (i = 0; i < n; i++)
114 cout << insCount - tree.
size() <<
" Items removed" << endl;
140static char doc[] =
"testAllTree -- A tester for all binary trees";
141static char argDoc[] =
"-n num_nodes -m seed_for_random -<tree type>\n"
145 {
"bin",
'b', 0, OPTION_ARG_OPTIONAL,
"pure binary tree" , 0},
146 {
"avl",
'a', 0, OPTION_ARG_OPTIONAL,
"avl tree" , 0},
147 {
"splay",
's', 0, OPTION_ARG_OPTIONAL,
"splay tree" , 0},
148 {
"redblack",
'r', 0, OPTION_ARG_OPTIONAL,
"red black tree" , 0},
149 {
"rand",
'd', 0, OPTION_ARG_OPTIONAL,
"randomized tree" , 0},
150 {
"treap",
'p', 0, OPTION_ARG_OPTIONAL,
"treap tree" , 0},
151 {
"nodes",
'n',
"num_nodes", OPTION_ARG_OPTIONAL,
152 "Specify the number of nodes to be generated", 0 },
153 {
"seed",
'm',
"seed_for_random", OPTION_ARG_OPTIONAL,
154 "Specify the seed for randon number generator", 0},
158static error_t
parser_opt(
int key,
char *,
struct argp_state *state)
170 if (state->argv[state->next] == NULL)
172 parsPtr->
n = strtol(state->argv[state->next], &end, 10);
173 if (*end !=
'\0' && *end !=
'\n')
179 parsPtr->
str =
"BinTree";
183 parsPtr->
str =
"AvlTree";
187 parsPtr->
str =
"RbTree";
191 parsPtr->
str =
"SplayTree";
195 parsPtr->
str =
"Treap";
199 parsPtr->
str =
"Randomized";
202 if (state->argv[state->next] == NULL)
204 parsPtr->
seed = strtol(state->argv[state->next], &end, 10);
205 if (*end !=
'\0' && *end !=
'\n')
210 default:
return ARGP_ERR_UNKNOWN;
217int main(
int argc,
char *argv[])
221 cout <<
"testAllTree -- stress-test for Aleph-w binary search trees\n"
223 <<
"Inserts, searches, and removes random keys in a DynMapTree backed by\n"
224 <<
"the chosen tree type, then reports path length, height, and counts.\n"
227 <<
" " << argv[0] <<
" -<tree> [-n num_nodes] [-m seed]\n"
229 <<
"Tree type (required; last wins if repeated):\n"
230 <<
" -b, --bin Pure (unbalanced) binary tree\n"
231 <<
" -a, --avl AVL tree\n"
232 <<
" -s, --splay Splay tree\n"
233 <<
" -r, --redblack Red-black tree\n"
234 <<
" -p, --treap Treap (randomized BST with priorities)\n"
235 <<
" -d, --rand Randomized tree\n"
238 <<
" -n num_nodes Number of keys to insert (default: 1000)\n"
239 <<
" -m seed Seed for the random number generator (default: current time)\n"
242 <<
" " << argv[0] <<
" -a -n 5000 # AVL tree with 5000 nodes\n"
243 <<
" " << argv[0] <<
" -p -n 10000 -m 42 # Treap, 10000 nodes, seed 42\n";
249 error_t status = argp_parse(&
argDefs, argc, argv, 0, 0, &pars);
257 unsigned long n = pars.
n;
261 cout <<
"testAllTree<" << pars.
str <<
"> " << n <<
" " << pars.
seed
272 test<Avl_Tree>(n,
r);
278 test<Rand_Tree>(n,
r);
281 test<Splay_Tree>(n,
r);
290 cout <<
"testAllTree<" << pars.
str <<
"> " << n <<
" " << pars.
seed
293 catch (exception & e)
295 cout <<
"**** Exception: " << e.what() << endl;
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
#define AH_ERROR(...)
Print an error message (always enabled).
Core header for the Aleph-w library.
WeightedDigraph::Node Node
size_t size_t int32_t value
Generic key-value map implemented on top of a binary search tree.
Data remove(const Key &key)
Deletes the pair key,data
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Data & find(const Key &key)
Find the value associated with key.
size_t height() const
Calculates and returns the height of the binary search tree.
const size_t & size() const
Returns the cardinality of the set.
size_t internal_path_length() const
Calculates and returns the length of the internal path of the tree search binary.
A random number generator with the sequences of GSL's gsl_rng_mt19937.
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
unsigned long uniform_int(const unsigned long n)
An integer in [0, n), each with the same probability, as gsl_rng_uniform_int(r, n).
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Parameters(int _n, int _seed)
static void printNode(Node *node, int, int)
const char * argp_program_version
static error_t parser_opt(int key, char *, struct argp_state *state)
const char * argp_program_bug_address
static struct argp_option options[]
static struct argp argDefs
AVL tree implementation (height-balanced BST).
Generic unbalanced binary search tree.
Dynamic key-value map based on balanced binary search trees.
Randomized binary search tree.
Red-Black tree implementation (bottom-up balancing).
Top-down splay tree implementation (without rank support).
Treap: randomized BST combining tree and heap properties.