OpenWalnut  1.5.0dev
WHistogramBasic.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 WHISTOGRAMBASIC_H
26 #define WHISTOGRAMBASIC_H
27 
28 #include <cstddef> // for std::size_t
29 #include <utility>
30 #include <vector>
31 
32 #include "WHistogram.h"
33 
34 
35 /**
36  * Container which associate values with (uniform width) bins (aka intervals or buckets). This class implements a very simple and easy to use
37  * generic histogram with uniform bucket sizes.
38  */
40 {
41 public:
42  /**
43  * Default constructor. Creates an empty histogram covering the specified min and max values with the specified number of buckets.
44  *
45  * \param min the smallest value
46  * \param max the largest value
47  * \param buckets the number of buckets
48  */
49  WHistogramBasic( double min, double max, std::size_t buckets = 1000 );
50 
51  /**
52  * Copy constructor. Creates a deep copy of the specified histogram.
53  *
54  * \param hist the histogram to copy.
55  */
56  WHistogramBasic( const WHistogramBasic& hist );
57 
58  /**
59  * Default destructor.
60  */
62 
63  /**
64  * Get the count of the specified bucket.
65  *
66  * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
67  *
68  * \return elements in the bucket.
69  */
70  virtual std::size_t operator[]( std::size_t index ) const;
71 
72  /**
73  * Get the count of the specified bucket. Testing if the position is valid.
74  *
75  * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
76  *
77  * \return elements in the bucket
78  */
79  virtual std::size_t at( std::size_t index ) const;
80 
81  /**
82  * Return the size of one specific bucket.
83  *
84  * \param index the width for this bucket is queried.
85  *
86  * \return the size of a bucket.
87  */
88  virtual double getBucketSize( std::size_t index = 0 ) const;
89 
90  /**
91  * Returns the actual interval associated with the given index. The interval is open, meaning that
92  * getIntervalForIndex( i ).second == getIntervalForIndex( i + 1 ).first but does not belong anymore to the interval itself but every value
93  * smaller than getIntervalForIndex( i ).second.
94  *
95  * \param index the intex
96  *
97  * \return the open interval.
98  */
99  virtual std::pair< double, double > getIntervalForIndex( std::size_t index ) const;
100 
101  /**
102  * Computes the number of inserted values so far.
103  *
104  * \return Number of values so far.
105  */
106  std::size_t valuesSize() const;
107 
108  /**
109  * Inserts a given value within the given range (min, max) into exactly one bin and increment its size.
110  *
111  * \param value Value to insert.
112  *
113  * \return The index of the bin the value was inserted into or the maximum size_t if it was out of range.
114  */
115  virtual std::size_t insert( double value );
116 
117 protected:
118 private:
119  /**
120  * Bins to associate with the values. Each bin has the width of m_intervalWidth;
121  */
122  std::vector< std::size_t > m_bins;
123 
124  /**
125  * The width of an interval is precomputed to save performance.
126  */
128 };
129 
130 #endif // WHISTOGRAMBASIC_H
Container which associate values with (uniform width) bins (aka intervals or buckets).
double m_intervalWidth
The width of an interval is precomputed to save performance.
virtual std::size_t insert(double value)
Inserts a given value within the given range (min, max) into exactly one bin and increment its size.
~WHistogramBasic()
Default destructor.
virtual std::pair< double, double > getIntervalForIndex(std::size_t index) const
Returns the actual interval associated with the given index.
std::vector< std::size_t > m_bins
Bins to associate with the values.
virtual std::size_t at(std::size_t index) const
Get the count of the specified bucket.
WHistogramBasic(double min, double max, std::size_t buckets=1000)
Default constructor.
virtual double getBucketSize(std::size_t index=0) const
Return the size of one specific bucket.
std::size_t valuesSize() const
Computes the number of inserted values so far.
virtual std::size_t operator[](std::size_t index) const
Get the count of the specified bucket.
Container which associate values with (uniform width) bins (aka intervals or buckets).
Definition: WHistogram.h:36