-
Notifications
You must be signed in to change notification settings - Fork 24
/
stats.h
89 lines (72 loc) · 1.83 KB
/
stats.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
//
// File: tpie_stats.h
// Author: Octavian Procopiuc <tavi@cs.duke.edu>
//
// $Id: tpie_stats.h,v 1.5 2004-08-12 12:35:32 jan Exp $
//
// The tpie_stats class for recording statistics. The parameter C is
// the number of statistics to be recorded.
//
#ifndef _TPIE_STATS_H
#define _TPIE_STATS_H
// Get definitions for working with Unix and Windows
#include <tpie/portability.h>
namespace tpie {
///////////////////////////////////////////////////////////////////////////
/// Encapsulates statistics about a TPIE object.
/// \sa stats_stream
///////////////////////////////////////////////////////////////////////////
template<int C>
class stats {
private:
// The array storing the C statistics.
TPIE_OS_OFFSET stats_[C];
public:
// Reset all counts to 0.
void reset() {
for (int i = 0; i < C; i++)
stats_[i] = 0;
}
// Default constructor. Set all counts to 0.
stats() {
reset();
}
// Copy constructor.
stats(const stats<C>& ts) {
for (int i = 0; i < C; i++)
stats_[i] = ts.stats_[i];
}
// Record ONE event of type t.
void record(int t) {
stats_[t]++;
}
// Record k events of type t.
void record(int t, TPIE_OS_OFFSET k) {
stats_[t] += k;
}
// Record the events stored in s.
void record(const stats<C>& s) {
for (int i = 0; i < C; i++)
stats_[i] += s.stats_[i];
}
// Set the number of type t events to k.
void set(int t, TPIE_OS_OFFSET k) {
stats_[t] = k;
}
// Inquire the number of type t events.
TPIE_OS_OFFSET get(int t) const {
return stats_[t];
}
// Destructor.
~stats() {}
};
template<int C>
const stats<C> operator-(const stats<C> & lhs,
const stats<C> & rhs) {
stats<C> res;
for (int i = 0; i < C; i++)
res.stats_[i] = lhs.stats_[i] - rhs.stats_[i];
return res;
}
} // tpie namespace
#endif //_TPIE_STATS_H