histogram.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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: