forked from floft/sprouts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.cpp
94 lines (87 loc) · 1.92 KB
/
util.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
88
89
90
91
92
93
94
#include "util.h"
#include <chrono>
#include <iostream>
#include <cstdlib>
#include <array>
#include <complex>
#include <random>
using namespace std;
/**************
*Description:
*Input:
*Output:
**************/
#if 0 // testing balanced_tree
namespace
{
initializer init1([]()
{
balanced_tree<float> t, t2;
t.insert(1.0);
t.insert(1.0);
t.insert(5.0);
t.insert(2.0);
t.insert(4.0);
t.insert(3.0);
t.insert(6.0);
cout << "tree :";
for(auto i = t.begin(); i != t.end(); i++)
cout << " " << *i;
cout << endl;
cout << "tree :";
for(auto i = t.begin(); i != t.end();)
{
auto v = *i;
i = t.erase(i);
cout << " " << v;
t.insert(v);
}
cout << endl;
t2 = move(t);
t = t2;
cout << "tree range :";
for(auto i = t.rangeBegin(2.0); i != t.rangeEnd(30); i++)
cout << " " << *i;
cout << endl;
t.erase(3);
cout << "tree :";
for(auto i = t.begin(); i != t.end(); i++)
cout << " " << *i;
cout << endl;
exit(0);
});
}
#endif // testing balanced_tree
#if 0 // testing solveCubic
namespace
{
void writeCubic(float a, float b, float c, float d)
{
cout << a << " + " << b << "x + " << c << "x^2 + " << d << "x^3 = 0\n";
float roots[3];
int rootCount = solveCubic(a, b, c, d, roots);
cout << rootCount << " root" << (rootCount != 1 ? "s" : "") << " :\n";
for(int i = 0; i < rootCount; i++)
{
cout << roots[i] << " : error " << (a + b * roots[i] + c * (roots[i] * roots[i]) + d * (roots[i] * roots[i] * roots[i])) << endl;
}
cout << endl;
}
initializer init2([]()
{
for(int i = 0; i < 20; i++)
{
writeCubic(rand() % 11 - 5, rand() % 11 - 5, rand() % 11 - 5, 0);
}
exit(0);
});
}
#endif // testing solveCubic
void * operator new(size_t sz) // for profiling
{
return malloc(sz);
}
void operator delete(void * ptr) // for profiling
{
free(ptr);
}