Aleph-w 3.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 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <https://www.gnu.org/licenses/>.
26*/
27
28# include <gsl/gsl_rng.h>
29# include <iostream>
30# include <memory>
31# include <tpl_dynBinHeap.H>
32# include <tpl_dynSetTree.H>
33
34using namespace std;
35
37{
38 void operator()(gsl_rng * r) const { gsl_rng_free(r); }
39};
40
41using GslRngHandle = std::unique_ptr<gsl_rng, GslRngDeleter>;
42
43template <class Tree>
44void test(size_t n, unsigned long seed)
45{
46 cout << "Testing for " << typeid(Tree).name() << endl
47 << endl;
49 gsl_rng_set(r.get(), seed % gsl_rng_max(r.get()));
50
51 Tree tree;
52 for (size_t i = 0; i < n; ++i)
53 {
54 auto val = gsl_rng_get(r.get());
55 auto node = new typename Tree::Node(val);
56 auto p = tree.insert(node);
57 if (p == nullptr)
58 delete node;
59 }
60
61 {
62 typename Tree::Iterator it = tree;
63 auto it_c = it;
64 auto it_m = move(it_c);
65 }
66
67 for (typename Tree::Iterator it(tree); it.has_curr(); it.next())
68 cout << it.get_curr()->get_key() << " " << endl;
69 cout << endl;
70
71 destroyRec(tree.getRoot());
72}
73
74void usage()
75{
76 cout << "test-tree-itor [n] [seed]" << endl
77 << endl;
78 exit(0);
79}
80
81int main(int argc, char *argv[])
82{
83 size_t n = 10;
84 unsigned long seed = 0;
85
86 try
87 {
88 if (argc > 1)
89 n = static_cast<size_t>(stoul(argv[1]));
90 if (argc > 2)
91 seed = stoul(argv[2]);
92 }
93 catch (...)
94 {
95 // Fallback to defaults
96 }
97
105}
106
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:237
void destroyRec(Node *&root) noexcept
Free recursively 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:132
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
@ Tree
Basic arc (in spanning tree).
STL namespace.
void operator()(gsl_rng *r) const
void test()
Definition test-comb.C:35
void usage()
std::unique_ptr< gsl_rng, GslRngDeleter > GslRngHandle
ValueArg< size_t > seed
Definition testHash.C:48
gsl_rng * r
Dynamic binary heap with node-based storage.
Dynamic set implementations based on balanced binary search trees.