-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomparator.h
More file actions
158 lines (123 loc) · 3.61 KB
/
comparator.h
File metadata and controls
158 lines (123 loc) · 3.61 KB
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
//
// Created by adam on 6/30/19.
//
#ifndef CUDADB_PROJECT_COMPARATOR_H
#define CUDADB_PROJECT_COMPARATOR_H
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include "recordType.h"
#include <thrust/device_reference.h>
struct Filter{
int operator()(const recordType rt) const {
return 0;
}
};
struct stringFilter:Filter
{
/**用于过滤字符串类型**/
const device_string key;
const device_string strValue;
const bool isEqualOp;
stringFilter(device_string _key, device_string _value, bool _opr) : key(_key), strValue(_value), isEqualOp(_opr) {}
__host__ __device__
int operator()(const recordType rt) const {
if(key.raw[0] == 'u'){
//uin
return !(rt.getUin() == strValue) ^ isEqualOp;
}
if(key.raw[0] == 'c' && key.raw[1] == 'o'){
//country
return !(rt.getCountry() == strValue) ^ isEqualOp;
}
if(key.raw[0] == 'p'){
//province
return !(rt.getProvince() == strValue) ^ isEqualOp;
}
if(key.raw[0] == 'c' && key.raw[1] == 'i'){
//city
return !(rt.getCity() == strValue) ^ isEqualOp;
}
if(key.raw[0] == 'g'){
//gender
return !(rt.getGender() == strValue) ^ isEqualOp;
}
if(key.raw[0] == 'e'){
//education
return !(rt.getEducationLevel() == strValue) ^ isEqualOp;
}
if(key.raw[0] == 'b'){
//brand
return !(rt.getBrand() == strValue) ^ isEqualOp;
}
if(key.raw[0] == 'm'){
//model
return !(rt.getModel() == strValue) ^ isEqualOp;
}
if(key.raw[0] == 'o'){
//operator
return !(rt.getNetworkOperator() == strValue) ^ isEqualOp;
}
if(key.raw[0] == 'n'){
//uin
return !(rt.getNetworkType() == strValue) ^ isEqualOp;
}
}
};
struct ageFilter:Filter {
/**用于过滤字符串类型**/
const device_string key;
const int intValue;
const device_string relationalOp;
ageFilter(device_string _key, int _value, device_string _opr) : key(_key), intValue(_value), relationalOp(_opr) {}
__host__ __device__
int operator()(const recordType rt) const {
if(key.raw[0] == 'a'){
//age
if(relationalOp.raw[0] == '='){
return rt.getAge() == intValue;
}
if(relationalOp.raw[0] == '>'){
if(relationalOp.cstr_len == 1){
return rt.getAge() > intValue;
}
if(relationalOp.cstr_len == 2){
return rt.getAge() >= intValue;
}
}
if(relationalOp.raw[0] == '<'){
if(rt.getAge()==-100){
// 若为未知
return 0;
}
if(relationalOp.cstr_len == 1){
return rt.getAge() < intValue;
}
if(relationalOp.cstr_len == 2){
return rt.getAge() <= intValue;
}
}
}
}
};
//
//struct andFilter{
// const struct Filter k1;
// const struct Filter k2;
// andFilter(const struct Filter _k1, const struct Filter _k2){
// k1=_k1;
// k2=_k2;
// }
// __host__ __device__
// int operator()(recordType rt) const{
// return k1(rt) & k2(rt);
// }
//};
struct is_odd
{
__host__ __device__
bool operator()(int x)
{
return x==1;
}
};
#endif //CUDADB_PROJECT_COMPARATOR_H