-
Notifications
You must be signed in to change notification settings - Fork 2
/
depthstats.h
60 lines (52 loc) · 1.26 KB
/
depthstats.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
#pragma once
#include <stdint.h>
#include <cmath>
#include <string>
#include "string.h"
using namespace std;
struct DepthStats {
uint32_t mindepth, maxdepth, num;
uint64_t sumdepth, sumdepthsq;
DepthStats(){
reset();
}
void reset(){
num = 0;
mindepth = 1000000000;
maxdepth = 0;
sumdepth = 0;
sumdepthsq = 0;
}
DepthStats & operator += (const DepthStats & o){
num += o.num;
sumdepth += o.sumdepth;
sumdepthsq += o.sumdepthsq;
if(mindepth > o.mindepth) mindepth = o.mindepth;
if(maxdepth < o.maxdepth) maxdepth = o.maxdepth;
return *this;
}
DepthStats operator + (const DepthStats & o) const {
DepthStats n = *this;
n += o;
return n;
}
void add(unsigned int depth){
num++;
if(mindepth > depth) mindepth = depth;
if(maxdepth < depth) maxdepth = depth;
sumdepth += depth;
sumdepthsq += depth*depth;
}
double avg() const {
if(num == 0) return 0.0;
return (double)sumdepth/num;
}
double std_dev() const {
if(num == 0) return 0.0;
return sqrt((double)sumdepthsq/num - ((double)sumdepth/num)*((double)sumdepth/num));
}
string to_s() const {
if(num == 0) return "num=0";
return to_str(avg(), 4) +", dev=" + to_str(std_dev(), 4) + ", min=" + to_str(mindepth) + ", max=" + to_str(maxdepth) + ", num=" + to_str(num);
}
};