histogram.h
Go to the documentation of this file.
00001 /* histogram.h
00002  */
00003 #ifndef _HISTOGRAM_H
00004 #define _HISTOGRAM_H
00005 
00006 #include <boost/scoped_array.hpp>
00007 #include <iosfwd>
00008 namespace osl
00009 {
00010   namespace stat
00011   {
00015     class Histogram
00016     {
00017       boost::scoped_array<double> data;
00018       size_t length_, width_;
00019       int start_;
00020       bool show_on_destruct;
00021     public:
00022       Histogram(size_t w, size_t len, int start=0, bool show_on_destruct=false);
00023       ~Histogram();
00024       size_t safeIndex(size_t i) const
00025       {
00026         return (i >= length_) ? length_-1 : i;
00027       }
00028       double& frequency(size_t i) { return data[safeIndex(i)]; }
00029       void add(int value, double weight=1.0) 
00030       {
00031         if (value < start_)
00032           value = 0;
00033         else
00034           value -= start_;
00035         frequency(value/width_) += weight; 
00036       }
00037       double frequency(size_t i) const { return data[safeIndex(i)]; }
00038       void show(std::ostream& os) const;
00039 
00040       size_t length() const { return length_; }
00041       size_t width() const { return width_; }
00042       int start() const { return start_; }
00043 
00045       void merge(const Histogram&);
00047       void showRatio(std::ostream& os, const Histogram& numerator) const;
00048     };
00049   } // namespace stat
00050   using stat::Histogram;
00051 } // namespace osl
00052 
00053 #endif /* _HISTOGRAM_H */
00054 // ;;; Local Variables:
00055 // ;;; mode:c++
00056 // ;;; c-basic-offset:2
00057 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines