-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.cpp
63 lines (57 loc) · 1.82 KB
/
part2.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
/*
* Copyright (c) 2019, Aditya Rohan
* Copyright (c) 2019, Aniket Pandey
*
* Submitted to:
* CS622A: 2019-20 Fall Semester. Assignment 2
*/
#include <experimental/filesystem>
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
using namespace std;
namespace fs = std::experimental::filesystem;
typedef long long int_t;
typedef std::vector <int_t> MyClassSet;
typedef std::map <int_t, MyClassSet> MyClassSetMap;
#define BLOCK_OFFSET 6
int main(int argc, char const *argv[]) {
int_t tid, block, time = 0;
int_t num_dist = 0, f_dist = 0;
string folder = "traces", output = "result/part2-cdf.out";
for (const auto& tracefile : fs::directory_iterator(folder)) {
std::ifstream infile (tracefile.path());
if (!infile.is_open()) {
cerr << "Tracefile " << tracefile.path().filename().string()
<< " could not be opened\n";
}
MyClassSetMap maps;
map <int_t, int_t> distance;
cout << "Processing file " << tracefile.path().filename().string()
<< endl;
while (infile >> tid >> block) {
block = block >> BLOCK_OFFSET;
maps[block].emplace_back(time);
time++;
}
// Segregate all blocks into their respective 'distances'
for(auto& elem : maps) {
for (int i = 0; i < elem.second.size() - 1; ++i) {
int_t cd = elem.second[i+1] - elem.second[i];
distance[cd]++;
num_dist++;
}
}
// Result Compilation
ofstream myfile;
myfile.open (output);
for(auto& elem : distance) {
f_dist += elem.second;
myfile << elem.first << ": " << (float) f_dist/(float)num_dist
<< endl;
}
myfile.close();
}
return 0;
}