-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkdtree.hpp
96 lines (85 loc) · 2.65 KB
/
kdtree.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
#ifndef KDTREE_HPP
#define KDTREE_HPP
#include <time.h>
#include <limits.h>
#include <float.h>
#include <fstream>
#include <boost/iostreams/device/mapped_file.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>
#include "radix.h"
#include "struct.hpp"
namespace QProcessor
{
class KDTree
{
public:
inline static uint32_t createTime(std::string mytime)
{
/*
std::vector<std::string> strs;
boost::split(strs,mytime,boost::is_any_of("/"));
int month = boost::lexical_cast<int>(strs[0]);
int day = boost::lexical_cast<int>(strs[1]);
int year = boost::lexical_cast<int>(strs[2]);
//Default
int hour = 12;
int min = 12;
int sec = 12;
*/
std::vector<std::string> strs;
boost::split(strs,mytime,boost::is_any_of("T"));
std::vector<std::string> date;
boost::split(date,strs[0],boost::is_any_of("-"));
std::vector<std::string> time;
boost::split(time,strs[1],boost::is_any_of(":"));
int month = boost::lexical_cast<int>(date[1]);
int day = boost::lexical_cast<int>(date[2]);
int year = boost::lexical_cast<int>(date[0]);
int hour = boost::lexical_cast<int>(time[0]);
int min = boost::lexical_cast<int>(time[1]);
int sec = boost::lexical_cast<int>(time[2]);
struct tm timeinfo;
memset(&timeinfo, 0, sizeof(timeinfo));
timeinfo.tm_year = year-1900;
timeinfo.tm_mon = month-1;
timeinfo.tm_mday = day;
timeinfo.tm_hour = hour;
timeinfo.tm_min = min;
timeinfo.tm_sec = sec;
timeinfo.tm_isdst = -1;
return mktime(&timeinfo);
};
inline uint32_t getUKey(const Point &point, int keyIndex)
{
switch (keyIndex)
{
case 0:
return point._id;
case 1:
return float2uint(point._lat);
case 2:
return float2uint(point._lon);
case 3:
return point._time;
default:
return 0;
}
};
KDTree(std::string csvfile);
QueryResult execute(const Query &q);
Iterator begin();
Iterator end();
void buildKdTree(KdNode *nodes, uint32_t *tmp, Point *points, uint64_t n, int depth, uint64_t thisNode, uint64_t &freeNode);
bool createKdTree(std::string csvfile);
bool csv2binary(std::string csvIn, std::string binOut);
private:
void searchKdTree(const KdNode *nodes, uint32_t root, uint32_t range[3][2], int depth, const Query &query, QueryResult &result);
uint32_t float2uint(float f) ;
boost::iostreams::mapped_file_source _fTree;
const KdNode * _nodes;
const KdNode * _endNode;
};
};
#endif