My Project
std
osl
stat
histogram.cc
Go to the documentation of this file.
1
/* histogram.cc
2
*/
3
#include "
osl/stat/histogram.h
"
4
#include <iostream>
5
#include <iomanip>
6
7
osl::stat::
8
Histogram::Histogram
(
size_t
w,
size_t
len,
int
s,
bool
sd)
9
: data(new double[len]), length_(len), width_(w), start_(s),
10
show_on_destruct(sd)
11
{
12
std::fill(&
data
[0], &
data
[0]+
length_
, 0);
13
}
14
osl::stat::
15
Histogram::~Histogram
()
16
{
17
if
(show_on_destruct)
18
show(std::cerr);
19
}
20
void
osl::stat::
21
Histogram::merge
(
const
Histogram
& o)
22
{
23
if
((width_ == o.
width_
)
24
&& (length_ == o.
length_
)
25
&& (start_ == o.
start_
))
26
{
27
for
(
size_t
i=0; i<length_; ++i)
28
{
29
data[i] += o.
data
[i];
30
}
31
}
32
}
33
34
void
osl::stat::
35
Histogram::show
(std::ostream& os)
const
36
{
37
int
value=start_;
38
for
(
size_t
i=0; i<length_; ++i, value+=width_)
39
{
40
os << std::setw(5) << value <<
" - "
<< std::setw(5);
41
os << value+(int)width_;
42
os <<
" "
<< std::setw(8) << (size_t)data[i] <<
"\n"
;
43
}
44
}
45
46
void
osl::stat::
47
Histogram::showRatio
(std::ostream& os,
const
Histogram
& o)
const
48
{
49
if
((width_ == o.
width_
)
50
&& (length_ == o.
length_
)
51
&& (start_ == o.
start_
))
52
{
53
int
value=start_;
54
for
(
size_t
i=0; i<length_; ++i, value+=width_)
55
{
56
os << std::setw(5) << value <<
" - "
<< std::setw(5);
57
if
(i+1 < length_)
58
os << value+(int)width_;
59
else
60
os <<
" "
;
61
os << std::setw(8) << o.
data
[i]
62
<< std::setw(8) << data[i]
63
<< std::setw(8) << std::setprecision(2)
64
<<
static_cast<
double
>
(o.
data
[i])/data[i] <<
"\n"
;
65
}
66
}
67
}
68
69
/* ------------------------------------------------------------------------- */
70
// ;;; Local Variables:
71
// ;;; mode:c++
72
// ;;; c-basic-offset:2
73
// ;;; End:
osl::stat::Histogram
ヒストグラム
Definition
histogram.h:16
osl::stat::Histogram::~Histogram
~Histogram()
Definition
histogram.cc:15
osl::stat::Histogram::length_
size_t length_
Definition
histogram.h:18
osl::stat::Histogram::show
void show(std::ostream &os) const
Definition
histogram.cc:35
osl::stat::Histogram::width_
size_t width_
Definition
histogram.h:18
osl::stat::Histogram::start_
int start_
Definition
histogram.h:19
osl::stat::Histogram::showRatio
void showRatio(std::ostream &os, const Histogram &numerator) const
\frac{*this}{numerator} を表示 length や width が異なっていたら何もしない
Definition
histogram.cc:47
osl::stat::Histogram::data
boost::scoped_array< double > data
Definition
histogram.h:17
osl::stat::Histogram::Histogram
Histogram(size_t w, size_t len, int start=0, bool show_on_destruct=false)
Definition
histogram.cc:8
osl::stat::Histogram::merge
void merge(const Histogram &)
結果を合算する length や width が異なっていたら何もしない
Definition
histogram.cc:21
histogram.h
Generated by
1.9.8