histogram.cc
Go to the documentation of this file.
/* histogram.cc
*/
#include "osl/stat/histogram.h"
#include <iostream>
#include <iomanip>
osl::stat::
Histogram::Histogram(size_t w, size_t len, int s, bool sd)
: data(new double[len]), length_(len), width_(w), start_(s),
show_on_destruct(sd)
{
std::fill(&data[0], &data[0]+length_, 0);
}
osl::stat::
Histogram::~Histogram()
{
if (show_on_destruct)
show(std::cerr);
}
void osl::stat::
Histogram::merge(const Histogram& o)
{
if ((width_ == o.width_)
&& (length_ == o.length_)
&& (start_ == o.start_))
{
for (size_t i=0; i<length_; ++i)
{
data[i] += o.data[i];
}
}
}
void osl::stat::
Histogram::show(std::ostream& os) const
{
int value=start_;
for (size_t i=0; i<length_; ++i, value+=width_)
{
os << std::setw(5) << value << " - " << std::setw(5);
os << value+(int)width_;
os << " " << std::setw(8) << (size_t)data[i] << "\n";
}
}
void osl::stat::
Histogram::showRatio(std::ostream& os, const Histogram& o) const
{
if ((width_ == o.width_)
&& (length_ == o.length_)
&& (start_ == o.start_))
{
int value=start_;
for (size_t i=0; i<length_; ++i, value+=width_)
{
os << std::setw(5) << value << " - " << std::setw(5);
if (i+1 < length_)
os << value+(int)width_;
else
os << " ";
os << std::setw(8) << o.data[i]
<< std::setw(8) << data[i]
<< std::setw(8) << std::setprecision(2)
<< static_cast<double>(o.data[i])/data[i] << "\n";
}
}
}
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
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::show_on_destruct
bool show_on_destruct
Definition histogram.h:20
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