-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.cpp
More file actions
111 lines (91 loc) · 2.33 KB
/
parser.cpp
File metadata and controls
111 lines (91 loc) · 2.33 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
#include <utility>
#include "ctime"
#include <fstream>
#include <sstream>
#include <vector>
#include <functional>
#include <parser.hpp>
#include "data_structure.cpp"
using namespace std;
using namespace itis;
vector<int> split(const std::string &s, char delimiter) {
vector<int> tokens;
string token;
istringstream tokenStream(s);
while (getline(tokenStream, token, delimiter)) {
tokens.push_back(stoi(token));
}
return tokens;
}
void Parser::process_data(const string &pathToInputFile, const string &pathToResult, int iterations) {
string line;
vector<float> insert;
vector<float> search;
vector<float> remove;
std::ofstream out;
out.open(pathToResult);
for (int j = 0; j < iterations; ++j) {
ifstream file(pathToInputFile);
while (getline(file, line)) {
auto *btree = new BTree(2);
vector<int> intValues = split(line, ' ');
//insert
double startTime = clock();
for (int value : intValues) {
btree->insert(value);
}
double endTime = clock();
insert.emplace_back(endTime - startTime);
if (out.is_open()) {
out << to_string(endTime - startTime) << " ";
}
//search
startTime = clock();
for (int value : intValues) {
btree->search(value);
}
endTime = clock();
search.emplace_back(endTime - startTime);
if (out.is_open()) {
out << to_string(endTime - startTime) << " ";
}
//remove
startTime = clock();
for (int value : intValues) {
btree->remove(value);
}
endTime = clock();
remove.emplace_back(endTime - startTime);
if (out.is_open()) {
out << to_string(endTime - startTime);
}
out << std::endl;
}
file.close();
}
float average = 0;
for (float f : insert) {
average += f;
}
average /= static_cast<float>(insert.size());
if (out.is_open()) {
out << "insert: " << to_string(average) << "\n";
}
average = 0;
for (float f : search) {
average += f;
}
average /= static_cast<float>(search.size());
if (out.is_open()) {
out << "search: " << to_string(average) << "\n";
}
average = 0;
for (float f : remove) {
average += f;
}
average /= static_cast<float>(remove.size());
if (out.is_open()) {
out << "remove: " << to_string(average) << "\n";
}
out.close();
}