-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.h
102 lines (90 loc) · 1.47 KB
/
global.h
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
#ifndef _GLOBAL_
#define _GLOBAL_
#include<iostream>
#include<cmath>
using namespace std;
class Stat{
public:
double min;
double max;
int no;
double sum;
double sumsq;
int tvar;
Stat()
{
max=no=sumsq=sum=0;
min = 10e18;
}
void print()
{
cout<<"Min: "<<min<<endl;
cout<<"Max: "<<max<<endl;
double avg = sum/no;
cout<<"Avg: "<<avg<<endl;
cout<<"Std dev:"<<sqrt((sumsq/no)-(avg*avg))<<endl;
}
void upd(double val)
{
min = val<min?val:min;
max = val>max?val:max;
sum+=val;
no++;
sumsq+=val*val;
}
void startUpdT()
{
tvar = 0;
}
void updT()
{
tvar++;
}
void endUpdT()
{
upd(tvar);
tvar = 0;
}
};
extern Stat TimeIns;
extern Stat TimePQ;
extern Stat TimeRQ;
extern Stat DAIns;
extern Stat DARQ;
extern Stat DAPQ;
extern int typeOfQ;
static void updDASt()
{
if(typeOfQ == 0) DAIns.startUpdT();
else if(typeOfQ == 1)DAPQ.startUpdT();
else if(typeOfQ == 2)DARQ.startUpdT();
}
static void updDAEnd()
{
if(typeOfQ == 0) DAIns.endUpdT();
else if(typeOfQ == 1)DAPQ.endUpdT();
else if(typeOfQ == 2)DARQ.endUpdT();
}
static void updDA()
{
if(typeOfQ == 0) DAIns.updT();
else if(typeOfQ == 1)DAPQ.updT();
else if(typeOfQ == 2)DARQ.updT();
}
static string numToStr(int num)
{
stringstream ss;
ss << num;
return ss.str();
}
static string nodefileName(const string& dataFile)
{
string prefix = "nodes/";
return prefix + dataFile;
}
static string datafileName(const string& dataFile)
{
string prefix = "data/";
return prefix + dataFile;
}
#endif