forked from BU-DiSC/cs561_templatezonemaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
135 lines (114 loc) · 4.72 KB
/
main.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
#include <fstream>
#include <vector>
#include <iostream>
#include <random>
#include <set>
#include <algorithm>
#include <functional>
#include <chrono>
#include "zonemaps.h"
#include "zonemaps.cpp"
using namespace std;
std::vector<int> generatePointQueries(std::vector<int> data, int n)
{
std::vector<int> queries(data.begin(), data.end());
// add a few elements out of range
int non_existing_counter = (data.size() * 0.1);
std::uniform_int_distribution<int> dist{n, (int)(1.8 * n)};
// Initialize the random_device
std::random_device rd;
// Seed the engine
std::mt19937_64 generator(rd());
std::set<int> non_existing;
while (non_existing.size() != non_existing_counter)
{
non_existing.insert(dist(generator));
}
queries.insert(queries.end(), non_existing.begin(), non_existing.end());
// shuffle indexes
std::random_shuffle(queries.begin(), queries.end());
return queries;
}
int main(int argc, char **argv)
{
if (argc < 3)
{
std::cout << "Usage: ./main <input_file> <test_case>" << std::endl;
return 0;
}
std::string input_file = argv[1];
std::string test_case = argv[2];
if (test_case != "test_pq" && test_case != "test_rq_1" && test_case != "test_rq_2" && test_case != "test_rq_3" && test_case != "test_rq_4")
{
std::cout << "<test_case> argument has to be one of the following: test_pq, test_rq_1, test_rq_2, test_rq_3 or test_rq_4" << std::endl;
return 0;
}
// read data
std::ifstream ifs;
std::vector<int> data;
ifs.open(input_file, std::ios::binary);
ifs.seekg(0, std::ios::end);
size_t filesize = ifs.tellg();
ifs.seekg(0, std::ios::beg);
data.resize(filesize / sizeof(int));
ifs.read((char *)data.data(), filesize);
//1. ----------------------------- initialize zonemap and build -----------------------------
//build zonemap
zonemap<int> zones(data, (uint)data.size() / 100);
if (test_case == "test_pq")
{
//2. ----------------------------- point queries -----------------------------
std::vector<int> queries = generatePointQueries(data, data.size());
auto start = std::chrono::high_resolution_clock::now();
// query from zonemaps here
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
unsigned long long point_query_time = duration.count();
std::cout << "Time taken to perform point queries from zonemap = " << point_query_time << " microseconds" << endl;
}
else if (test_case == "test_rq_1")
{
//3. ----------------------------- range queries -----------------------------
auto start = std::chrono::high_resolution_clock::now();
// range query from zonemaps here
int n = data.size();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
unsigned long long range_query_time = duration.count();
std::cout << "Time taken to perform range query 1 from zonemap = " << range_query_time << " microseconds" << endl;
}
else if (test_case == "test_rq_2")
{
//3. ----------------------------- range queries -----------------------------
auto start = std::chrono::high_resolution_clock::now();
// range query from zonemaps here
int n = data.size();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
unsigned long long range_query_time = duration.count();
std::cout << "Time taken to perform range query 2 from zonemap = " << range_query_time << " microseconds" << endl;
}
else if (test_case == "test_rq_3")
{
//3. ----------------------------- range queries -----------------------------
auto start = std::chrono::high_resolution_clock::now();
// range query from zonemaps here
int n = data.size();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
unsigned long long range_query_time = duration.count();
std::cout << "Time taken to perform range query 3 from zonemap = " << range_query_time << " microseconds" << endl;
}
else if (test_case == "test_rq_4")
{
//3. ----------------------------- range queries -----------------------------
auto start = std::chrono::high_resolution_clock::now();
// range query from zonemaps here
int n = data.size();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
unsigned long long range_query_time = duration.count();
std::cout << "Time taken to perform range query 4 from zonemap = " << range_query_time << " microseconds" << endl;
}
return 0;
}