OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 <utility>
29 
30 #include "WExportCommon.h"
31 
32 /**
33  * Container which associate values with (uniform width) bins (aka intervals or buckets). This class implements the abstract interface and
34  * therefore builds the base class for all histogram classes. The interface also allows programming histogram of different bucket sizes.
35  */
36 class OWCOMMON_EXPORT WHistogram // NOLINT
37 {
38 public:
39  /**
40  * Default constructor. Creates an empty histogram covering the specified min and max values with the specified number of buckets.
41  *
42  * \param min the smallest value
43  * \param max the largest value
44  * \param buckets the number of buckets
45  */
46  WHistogram( double min, double max, size_t buckets = 1000 );
47 
48  /**
49  * Copy constructor. Creates a deep copy of the specified histogram.
50  *
51  * \param hist the histogram to copy.
52  */
53  WHistogram( const WHistogram& hist );
54 
55  /**
56  * Default destructor.
57  */
58  virtual ~WHistogram();
59 
60  /**
61  * Get the count of the specified bucket.
62  *
63  * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
64  *
65  * \return elements in the bucket.
66  */
67  virtual size_t operator[]( size_t index ) const = 0;
68 
69  /**
70  * Get the count of the specified bucket. Testing if the position is valid.
71  *
72  * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
73  *
74  * \return elements in the bucket
75  */
76  virtual size_t at( size_t index ) const = 0;
77 
78  /**
79  * Returns the number of buckets in the histogram with the actual mapping.
80  *
81  * \return number of buckets
82  */
83  virtual size_t size() const;
84 
85  /**
86  * Returns the minimum value.
87  *
88  * \return minimum
89  */
90  virtual double getMinimum() const;
91 
92  /**
93  * Returns the maximum value.
94  *
95  * \return maximum
96  */
97  virtual double getMaximum() const;
98 
99  /**
100  * Return the size of one specific bucket.
101  *
102  * \param index the width for this bucket is queried.
103  *
104  * \return the size of a bucket.
105  */
106  virtual double getBucketSize( size_t index = 0 ) const = 0;
107 
108  /**
109  * Returns the actual interval associated with the given index. The interval is open, meaning that
110  * getIntervalForIndex( i ).second == getIntervalForIndex( i + 1 ).first but does not belong anymore to the interval itself but every value
111  * smaller than getIntervalForIndex( i ).second.
112  *
113  * \param index the intex
114  *
115  * \return the open interval.
116  */
117  virtual std::pair< double, double > getIntervalForIndex( size_t index ) const = 0;
118 
119 protected:
120 
121  /**
122  * The smallest value
123  */
124  double m_minimum;
125 
126  /**
127  * The biggest value
128  */
129  double m_maximum;
130 
131  /**
132  * The number of buckets.
133  */
134  double m_nbBuckets;
135 
136 private:
137 };
138 
139 #endif // WHISTOGRAM_H