OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WHISTOGRAMBASIC_H 00026 #define WHISTOGRAMBASIC_H 00027 00028 #include <utility> 00029 #include <vector> 00030 00031 #include "WHistogram.h" 00032 00033 00034 /** 00035 * Container which associate values with (uniform width) bins (aka intervals or buckets). This class implements a very simple and easy to use 00036 * generic histogram with uniform bucket sizes. 00037 */ 00038 class WHistogramBasic: public WHistogram 00039 { 00040 public: 00041 /** 00042 * Default constructor. Creates an empty histogram covering the specified min and max values with the specified number of buckets. 00043 * 00044 * \param min the smallest value 00045 * \param max the largest value 00046 * \param buckets the number of buckets 00047 */ 00048 WHistogramBasic( double min, double max, size_t buckets = 1000 ); 00049 00050 /** 00051 * Copy constructor. Creates a deep copy of the specified histogram. 00052 * 00053 * \param hist the histogram to copy. 00054 */ 00055 WHistogramBasic( const WHistogramBasic& hist ); 00056 00057 /** 00058 * Default destructor. 00059 */ 00060 ~WHistogramBasic(); 00061 00062 /** 00063 * Get the count of the specified bucket. 00064 * 00065 * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values. 00066 * 00067 * \return elements in the bucket. 00068 */ 00069 virtual size_t operator[]( size_t index ) const; 00070 00071 /** 00072 * Get the count of the specified bucket. Testing if the position is valid. 00073 * 00074 * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values. 00075 * 00076 * \return elements in the bucket 00077 */ 00078 virtual size_t at( size_t index ) const; 00079 00080 /** 00081 * Return the size of one specific bucket. 00082 * 00083 * \param index the width for this bucket is queried. 00084 * 00085 * \return the size of a bucket. 00086 */ 00087 virtual double getBucketSize( size_t index = 0 ) const; 00088 00089 /** 00090 * Returns the actual interval associated with the given index. The interval is open, meaning that 00091 * getIntervalForIndex( i ).second == getIntervalForIndex( i + 1 ).first but does not belong anymore to the interval itself but every value 00092 * smaller than getIntervalForIndex( i ).second. 00093 * 00094 * \param index the intex 00095 * 00096 * \return the open interval. 00097 */ 00098 virtual std::pair< double, double > getIntervalForIndex( size_t index ) const; 00099 00100 /** 00101 * Computes the number of inserted values so far. 00102 * 00103 * \return Number of values so far. 00104 */ 00105 size_t valuesSize() const; 00106 00107 /** 00108 * Inserts a given value within the given range (min, max) into exactly one bin and increment its size. 00109 * 00110 * \param value Value to insert. 00111 */ 00112 virtual void insert( double value ); 00113 00114 protected: 00115 private: 00116 /** 00117 * Bins to associate with the values. Each bin has the width of m_intervalWidth; 00118 */ 00119 std::vector< size_t > m_bins; 00120 00121 /** 00122 * The width of an interval is precomputed to save performance. 00123 */ 00124 double m_intervalWidth; 00125 }; 00126 00127 #endif // WHISTOGRAMBASIC_H