-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclosest_pair_helper.hpp
101 lines (80 loc) · 2.1 KB
/
closest_pair_helper.hpp
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
95
96
97
98
99
100
101
#ifndef __CLOSEST_PAIR_HELPER_HPP__
#define __CLOSEST_PAIR_HELPER_HPP__
#include <iostream>
#include <string>
#include <stout/strings.hpp>
using std::endl;
using std::cout;
using std::string;
using std::vector;
using std::queue;
namespace mesos {
string vectorToString(vector<double>& vec) {
string result;
result.append(stringify<size_t>(vec.size()));
result.push_back('\0');
for (size_t i = 0; i < vec.size(); i++) {
result.append(std::to_string(vec[i]));
result.push_back('\0');
}
return result;
}
vector<double> stringToVector(const string& str) {
const char *data = str.c_str();
string lenStr = data;
size_t len = numify<size_t>(data).get();
data += lenStr.length() + 1;
vector<double> result;
for (size_t i = 0; i < len; i ++) {
string s = data;
data += s.length() + 1;
result.push_back(stod(s));
}
return result;
}
};
const int32_t NOT_SET = -1;
enum Direction{
LEFT,
RIGHT,
NONE
};
struct Point{
double x,y;
Point(double _x, double _y)
: x(_x), y(_y) {}
};
double calcDist(Point p1, Point p2){
return sqrt( ((p1.x - p2.x) * (p1.x - p2.x)) +
((p1.y - p2.y) * (p1.y - p2.y)) );
}
struct SplitInfo {
int left, right, parent;
double lMinDist = NOT_SET, rMinDist = NOT_SET;
Direction dir;
void printSplitInfo() {
cout << "left = " << left << endl;
cout << "right = " << right << endl;
cout << "parent = " << parent << endl;
cout << "dir = " << dir << endl;
cout << "lMinDist " << lMinDist << endl;
cout << "rMinDist " << rMinDist << endl;
cout << "----" << endl << endl;
}
SplitInfo(int _left, int _right, int _parent, Direction _dir)
:left(_left), right(_right), parent(_parent),
lMinDist(double(NOT_SET)), rMinDist(double(NOT_SET)),
dir(_dir) {}
string convertToString()
{
vector<double> vec;
vec.push_back((double)left);
vec.push_back((double)right);
vec.push_back((double)parent);
vec.push_back((double)lMinDist);
vec.push_back((double)rMinDist);
vec.push_back((double)dir);
return stringify(vec);
}
};
#endif // __CLOSEST_PAIR_HELPER_HPP__