OpenWalnut  1.5.0dev
WHistogram.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WHISTOGRAM_H
26 #define WHISTOGRAM_H
27 
28 #include <cstddef> // for std::size_t
29 #include <utility>
30 
31 /**
32  * Container which associate values with (uniform width) bins (aka intervals or buckets). This class implements the abstract interface and
33  * therefore builds the base class for all histogram classes. The interface also allows programming histogram of different bucket sizes.
34  */
35 class WHistogram // NOLINT
36 {
37 public:
38  /**
39  * Default constructor. Creates an empty histogram covering the specified min and max values with the specified number of buckets.
40  *
41  * \param min the smallest value
42  * \param max the largest value
43  * \param buckets the number of buckets
44  */
45  WHistogram( double min, double max, std::size_t buckets = 1000 );
46 
47  /**
48  * Copy constructor. Creates a deep copy of the specified histogram.
49  *
50  * \param hist the histogram to copy.
51  */
52  WHistogram( const WHistogram& hist );
53 
54  /**
55  * Default destructor.
56  */
57  virtual ~WHistogram();
58 
59  /**
60  * Get the count of the specified bucket.
61  *
62  * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
63  *
64  * \return elements in the bucket.
65  */
66  virtual std::size_t operator[]( std::size_t index ) const = 0;
67 
68  /**
69  * Get the count of the specified bucket. Testing if the position is valid.
70  *
71  * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
72  *
73  * \return elements in the bucket
74  */
75  virtual std::size_t at( std::size_t index ) const = 0;
76 
77  /**
78  * Returns the number of buckets in the histogram with the actual mapping.
79  *
80  * \return number of buckets
81  */
82  virtual std::size_t size() const;
83 
84  /**
85  * Returns the minimum value.
86  *
87  * \return minimum
88  */
89  virtual double getMinimum() const;
90 
91  /**
92  * Returns the maximum value.
93  *
94  * \return maximum
95  */
96  virtual double getMaximum() const;
97 
98  /**
99  * Return the size of one specific bucket.
100  *
101  * \param index the width for this bucket is queried.
102  *
103  * \return the size of a bucket.
104  */
105  virtual double getBucketSize( std::size_t index = 0 ) const = 0;
106 
107  /**
108  * Returns the actual interval associated with the given index. The interval is open, meaning that
109  * getIntervalForIndex( i ).second == getIntervalForIndex( i + 1 ).first but does not belong anymore to the interval itself but every value
110  * smaller than getIntervalForIndex( i ).second.
111  *
112  * \param index the intex
113  *
114  * \return the open interval.
115  */
116  virtual std::pair< double, double > getIntervalForIndex( std::size_t index ) const = 0;
117 
118 protected:
119  /**
120  * The smallest value
121  */
122  double m_minimum;
123 
124  /**
125  * The biggest value
126  */
127  double m_maximum;
128 
129  /**
130  * The number of buckets.
131  */
132  double m_nbBuckets;
133 
134 private:
135 };
136 
137 #endif // WHISTOGRAM_H
138 
Container which associate values with (uniform width) bins (aka intervals or buckets).
Definition: WHistogram.h:36
virtual std::pair< double, double > getIntervalForIndex(std::size_t index) const =0
Returns the actual interval associated with the given index.
double m_minimum
The smallest value.
Definition: WHistogram.h:122
virtual double getBucketSize(std::size_t index=0) const =0
Return the size of one specific bucket.
virtual std::size_t size() const
Returns the number of buckets in the histogram with the actual mapping.
Definition: WHistogram.cpp:54
virtual double getMinimum() const
Returns the minimum value.
Definition: WHistogram.cpp:59
virtual std::size_t at(std::size_t index) const =0
Get the count of the specified bucket.
WHistogram(double min, double max, std::size_t buckets=1000)
Default constructor.
Definition: WHistogram.cpp:30
virtual std::size_t operator[](std::size_t index) const =0
Get the count of the specified bucket.
double m_nbBuckets
The number of buckets.
Definition: WHistogram.h:132
virtual ~WHistogram()
Default destructor.
Definition: WHistogram.cpp:50
double m_maximum
The biggest value.
Definition: WHistogram.h:127
virtual double getMaximum() const
Returns the maximum value.
Definition: WHistogram.cpp:64