Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test-tree-itor.C
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32
33# include <ah-random.H>
34# include <iostream>
35# include <memory>
36# include <tpl_dynBinHeap.H>
37# include <tpl_dynSetTree.H>
38
39using namespace std;
40
41template <class Tree>
42void test(size_t n, unsigned long seed)
43{
44 cout << "Testing for " << typeid(Tree).name() << endl
45 << endl;
47
48 Tree tree;
49 for (size_t i = 0; i < n; ++i)
50 {
51 auto val = r.get();
52 auto node = new typename Tree::Node(val);
53 auto p = tree.insert(node);
54 if (p == nullptr)
55 delete node;
56 }
57
58 {
59 typename Tree::Iterator it = tree;
60 auto it_c = it;
61 auto it_m = move(it_c);
62 }
63
64 for (typename Tree::Iterator it(tree); it.has_curr(); it.next())
65 cout << it.get_curr()->get_key() << " " << endl;
66 cout << endl;
67
68 destroyRec(tree.getRoot());
69}
70
71void usage()
72{
73 cout << "test-tree-itor [n] [seed]" << endl
74 << endl;
75 exit(0);
76}
77
78int main(int argc, char *argv[])
79{
80 size_t n = 10;
81 unsigned long seed = 0;
82
83 try
84 {
85 if (argc > 1)
86 n = static_cast<size_t>(stoul(argv[1]));
87 if (argc > 2)
88 seed = stoul(argv[2]);
89 }
90 catch (...)
91 {
92 // Fallback to defaults
93 }
94
95 test<BinTree<long>>(n, seed);
96 test<Avl_Tree<long>>(n, seed);
97 test<Splay_Tree<long>>(n, seed);
98 test<Rb_Tree<long>>(n, seed);
99 test<Rand_Tree<long>>(n, seed);
100 test<Treap<long>>(n, seed);
101 test<Treap_Rk<long>>(n, seed);
102}
103
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
int main()
A random number generator with the sequences of GSL's gsl_rng_mt19937.
Definition ah-random.H:147
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
Definition ah-random.H:259
unsigned long get() noexcept
The next number, as operator()().
Definition ah-random.H:289
QuadTree - Hierarchical spatial index for 2D points.
Definition quadtree.H:126
QuadNode Node
Definition quadtree.H:128
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
Definition quadtree.H:281
void destroyRec(Node *&root) noexcept
Free all the memory occupied by the tree root
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
Definition ahDefs.C:125
@ Tree
Basic arc (in spanning tree).
STL namespace.
void test()
Definition test-comb.C:40
void usage()
ValueArg< size_t > seed
Definition testHash.C:53
Gsl_Compatible_Rng r
Dynamic binary heap with node-based storage.
Dynamic set implementations based on balanced binary search trees.