-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint.cpp
243 lines (216 loc) · 5.68 KB
/
point.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include <assert.h>
#include "point.h"
using namespace std;
void* newPointVector(uint64_t step, uint64_t& mem){
void *point;
switch(step){
case 2:
point = new vector<TemPoint<2> >();
mem = ((vector<TemPoint<2> >*)point)->capacity() * sizeof(TemPoint<2>);
break;
case 3:
point = new vector<TemPoint<3> >();
mem = ((vector<TemPoint<3> >*)point)->capacity() * sizeof(TemPoint<3>);
break;
case 4:
point = new vector<TemPoint<4> >();
mem = ((vector<TemPoint<4> >*)point)->capacity() * sizeof(TemPoint<4>);
break;
default:
point = new vector<TemPoint<8> >();
mem = ((vector<TemPoint<8> >*)point)->capacity() * sizeof(TemPoint<8>);
}
return point;
}
void *newPointVector(uint64_t step, uint64_t size, uint64_t& mem){
void *point;
switch(step){
case 2:
point = new vector<TemPoint<2> >();
((vector<TemPoint<2> >*)point)->reserve(size);
mem = ((vector<TemPoint<2> >*)point)->capacity() * sizeof(TemPoint<2>);
break;
case 3:
point = new vector<TemPoint<3> >();
((vector<TemPoint<3> >*)point)->reserve(size);
mem = ((vector<TemPoint<3> >*)point)->capacity() * sizeof(TemPoint<3>);
break;
case 4:
point = new vector<TemPoint<4> >();
((vector<TemPoint<4> >*)point)->reserve(size);
mem = ((vector<TemPoint<4> >*)point)->capacity() * sizeof(TemPoint<4>);
break;
default:
point = new vector<TemPoint<8> >();
((vector<TemPoint<8> >*)point)->reserve(size);
mem = ((vector<TemPoint<8> >*)point)->capacity() * sizeof(TemPoint<8>);
}
return point;
}
uint64_t pointGetX(void*point, uint64_t step, uint64_t idx){
switch(step){
case 2:
return (*(vector<TemPoint<2> >*)point)[idx].m_x;
break;
case 3:
return (*(vector<TemPoint<3> >*)point)[idx].m_x;
break;
case 4:
return (*(vector<TemPoint<4> >*)point)[idx].m_x;
break;
default:
return (*(vector<TemPoint<8> >*)point)[idx].m_x;
}
}
uint64_t pointGetY(void* point, uint64_t step, uint64_t idx){
switch(step){
case 2:
return (*(vector<TemPoint<2> >*)point)[idx].m_y;
break;
case 3:
return (*(vector<TemPoint<3> >*)point)[idx].m_y;
break;
case 4:
return (*(vector<TemPoint<4> >*)point)[idx].m_y;
break;
default:
return (*(vector<TemPoint<8> >*)point)[idx].m_y;
}
}
void pointPushBack(void * point, uint64_t step, uint64_t x, uint64_t y){
switch(step){
case 2:
((vector<TemPoint<2> >*)point)->push_back(TemPoint<2>(x, y));
return;
break;
case 3:
((vector<TemPoint<3> >*)point)->push_back(TemPoint<3>(x, y));
return;
break;
case 4:
((vector<TemPoint<4> >*)point)->push_back(TemPoint<4>(x, y));
return;
break;
default:
((vector<TemPoint<8> >*)point)->push_back(TemPoint<8>(x, y));
return;
}
}
uint64_t pointSize(void * point, uint64_t step){
uint64_t size;
switch(step){
case 2:
size = ((vector<TemPoint<2> >*)point)->size();
break;
case 3:
size = ((vector<TemPoint<3> >*)point)->size();
break;
case 4:
size = ((vector<TemPoint<4> >*)point)->size();
break;
default:
size = ((vector<TemPoint<8> >*)point)->size();
}
return size;
}
// static bool cmp_x(TemPoint<8> a, TemPoint<8> b){
// return a.m_x < b.m_x;
// }
// static bool cmp_y(TemPoint<8> a, TemPoint<8> b){
// return a.m_y < b.m_y;
// }
static bool cmp_x2(TemPoint<2> a, TemPoint<2> b){
return a.m_x < b.m_x;
}
static bool cmp_y2(TemPoint<2> a, TemPoint<2> b){
return a.m_y < b.m_y;
}
static bool cmp_x3(TemPoint<3> a, TemPoint<3> b){
return a.m_x < b.m_x;
}
static bool cmp_y3(TemPoint<3> a, TemPoint<3> b){
return a.m_y < b.m_y;
}
static bool cmp_x4(TemPoint<4> a, TemPoint<4> b){
return a.m_x < b.m_x;
}
static bool cmp_y4(TemPoint<4> a, TemPoint<4> b){
return a.m_y < b.m_y;
}
static bool cmp_x8(TemPoint<8> a, TemPoint<8> b){
return a.m_x < b.m_x;
}
static bool cmp_y8(TemPoint<8> a, TemPoint<8> b){
return a.m_y < b.m_y;
}
void point_nth_element(void* point, uint64_t step, uint64_t kth, pair<uint64_t, uint64_t> range, int32_t depth){
uint64_t size = range.second - range.first + 1;
switch(step){
case 2:
{
vector<TemPoint<2> >* vp = (vector<TemPoint<2> >*)point;
vector<TemPoint<2> >::iterator it = vp->begin();
vector<TemPoint<2> >::iterator beg = it + range.first;
if(depth % 2 == 1)
nth_element(beg, beg + kth, beg + size, cmp_x2);
else
nth_element(beg, beg + kth, beg + size, cmp_y2);
break;
}
case 3:
{
vector<TemPoint<3> >* vp = (vector<TemPoint<3> >*)point;
vector<TemPoint<3> >::iterator it = vp->begin();
vector<TemPoint<3> >::iterator beg = it + range.first;
if(depth % 2 == 1)
nth_element(beg, beg + kth, beg + size, cmp_x3);
else
nth_element(beg, beg + kth, beg + size, cmp_y3);
break;
}
case 4:
{
vector<TemPoint<4> >* vp = (vector<TemPoint<4> >*)point;
vector<TemPoint<4> >::iterator it = vp->begin();
vector<TemPoint<4> >::iterator beg = it + range.first;
if(depth % 2 == 1)
nth_element(beg, beg + kth, beg + size, cmp_x4);
else
nth_element(beg, beg + kth, beg + size, cmp_y4);
break;
}
default:
{
vector<TemPoint<8> >* vp = (vector<TemPoint<8> >*)point;
vector<TemPoint<8> >::iterator it = vp->begin();
vector<TemPoint<8> >::iterator beg = it + range.first;
if(depth % 2 == 1)
nth_element(beg, beg + kth, beg + size, cmp_x8);
else
nth_element(beg, beg + kth, beg + size, cmp_y8);
return;
}
}
}
void deletePoint(void *point, uint64_t step){
if(point == NULL){
assert(false);
}
switch(step){
case 2:
delete (vector<TemPoint<2> >*)point;
return;
break;
case 3:
delete (vector<TemPoint<3> >*)point;
return;
break;
case 4:
delete (vector<TemPoint<4> >*)point;
return;
break;
default:
delete (vector<TemPoint<8> >*)point;
return;
}
}