forked from lemire/EWAHBoolArray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample3.cpp
79 lines (67 loc) · 1.84 KB
/
example3.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
#include <vector>
#include <iostream>
#include <unordered_map>
#include <string>
#include <ewah.h>
#include <string>
#include <algorithm>
#include <fstream>
#include <sstream>
using namespace std;
/**
* Simple DEMO to test the intersects function
*/
unordered_map<string, EWAHBoolArray<uint32_t>> indexColumn(vector<string> col) {
unordered_map<string, EWAHBoolArray<uint32_t>> indexes;
for (size_t i = 0; i < col.size(); i++) {
indexes[col[i]].set(i);
}
return indexes;
}
int main() {
// read the data from the CSV file
vector<string> col1, col2;
ifstream infile("data/data.csv");
while (infile) {
string s;
if (!getline(infile, s))
break;
istringstream ss(s);
int numCommas = 0;
while (ss) {
if (!getline(ss, s, ','))
break;
if (numCommas == 0) {
col1.push_back(s);
numCommas++;
} else {
col2.push_back(s);
numCommas = 0;
}
}
}
unordered_map<string, EWAHBoolArray<uint32_t>> index1 = indexColumn(col1);
unordered_map<string, EWAHBoolArray<uint32_t>> index2 = indexColumn(col2);
size_t testcount = 0;
for (unordered_map<string, EWAHBoolArray<uint32_t>>::iterator i =
index1.begin();
i != index1.end(); ++i) {
EWAHBoolArray<uint32_t> &bitmap1 = i->second;
for (unordered_map<string, EWAHBoolArray<uint32_t>>::iterator j =
index2.begin();
j != index2.end(); ++j) {
EWAHBoolArray<uint32_t> &bitmap2 = j->second;
bool intersect = bitmap1.intersects(bitmap2);
EWAHBoolArray<uint32_t> result;
testcount++;
bitmap1.logicaland(bitmap2, result);
if (intersect) {
assert(result.numberOfOnes() > 0);
} else {
assert(result.numberOfOnes() == 0);
}
}
}
cout << "Ran " << testcount << " tests. Your code is probably ok. " << endl;
return 0;
}