-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
87 lines (72 loc) · 2.43 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//============================================================================
// Name : main.cpp
// Author : botcs
// Version :
// Copyright : bcs
// Description : Hello World in C++, Ansi-style
//============================================================================
#include "kdtree.h"
#include <algorithm>
#include <cmath>
#include <ctime>
#include <fstream>
#include <iostream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include "presort.h"
#include <chrono>
#include <random>
using namespace std;
using c = vector<double>;
using p = pair<c, string>;
int main() {
try {
cout << "TEST with large data\n ********************* \n";
kdtree<3, double, string> test_bal, test_unbal, new_test;
vector<p> test;
for (int i = 0; i < 20; i++)
for (int j = 0; j < 20; j++)
for (int k = 0; k < 20; k++)
test.push_back(p{c{i, j, k}, ""});
// test.push_back(p{c{0,0,0}, ""});
cout << test.size() << " POINTS GENERATED\n";
auto t = clock();
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
shuffle(test.begin(), test.end(), std::default_random_engine(seed));
cout << "Shuffled them in " << clock() - t << "miliseconds \n";
/*for (auto& i : test) {
cout<<"(";
for (auto& c : i.first) cout<<c<<';';
cout<<")\n";
}*/
t = clock();
auto PS = presort(test);
cout << "Sorting finished in " << clock() - t << " miliseconds\n";
t = clock();
ins(test_bal, PS[0], PS[1], PS[2]);
cout << "pre-balanced Inserting finished in " << clock() - t
<< " miliseconds\n";
cout << "balanced insert HEIGHT: " << test_bal.height << '\n';
t = clock();
for (auto &i : test)
test_unbal.insert(i.first, i.second);
cout << "unbalanced Inserting finished in " << clock() - t
<< " miliseconds\n";
cout << "unbalanced insert HEIGHT: " << test_unbal.height << '\n';
t = clock();
new_test.insert(test);
cout << "new Inserting finished in " << clock() - t << " miliseconds\n";
cout << "ITEM COUNT: " << test.size()
<< " new_test size: " << new_test.size() << '\n';
cout << "new insert HEIGHT: " << new_test.height << '\n';
// test_unbal.print();
// test_bal.print();
cout << " **************************************\n";
}
catch (const exception &e) {
cout << "HIBA: " << e.what() << endl;
}
return 0;
}