OpenWalnut  1.4.0
WHistogram.h
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 WHISTOGRAM_H
00026 #define WHISTOGRAM_H
00027 
00028 #include <utility>
00029 
00030 
00031 
00032 /**
00033  * Container which associate values with (uniform width) bins (aka intervals or buckets). This class implements the abstract interface and
00034  * therefore builds the base class for all histogram classes. The interface also allows programming histogram of different bucket sizes.
00035  */
00036 class WHistogram // NOLINT
00037 {
00038 public:
00039     /**
00040      * Default constructor. Creates an empty histogram covering the specified min and max values with the specified number of buckets.
00041      *
00042      * \param min the smallest value
00043      * \param max the largest value
00044      * \param buckets the number of buckets
00045      */
00046     WHistogram( double min, double max, size_t buckets = 1000 );
00047 
00048     /**
00049      * Copy constructor. Creates a deep copy of the specified histogram.
00050      *
00051      * \param hist the histogram to copy.
00052      */
00053     WHistogram( const WHistogram& hist );
00054 
00055     /**
00056      * Default destructor.
00057      */
00058     virtual ~WHistogram();
00059 
00060     /**
00061      * Get the count of the specified bucket.
00062      *
00063      * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
00064      *
00065      * \return elements in the bucket.
00066      */
00067     virtual size_t operator[]( size_t index ) const = 0;
00068 
00069     /**
00070      * Get the count of the specified bucket. Testing if the position is valid.
00071      *
00072      * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
00073      *
00074      * \return elements in the bucket
00075      */
00076     virtual size_t at( size_t index ) const = 0;
00077 
00078     /**
00079      * Returns the number of buckets in the histogram with the actual mapping.
00080      *
00081      * \return number of buckets
00082      */
00083     virtual size_t size() const;
00084 
00085     /**
00086      * Returns the minimum value.
00087      *
00088      * \return minimum
00089      */
00090     virtual double getMinimum() const;
00091 
00092     /**
00093      * Returns the maximum value.
00094      *
00095      * \return maximum
00096      */
00097     virtual double getMaximum() const;
00098 
00099     /**
00100      * Return the size of one specific bucket.
00101      *
00102      * \param index the width for this bucket is queried.
00103      *
00104      * \return the size of a bucket.
00105      */
00106     virtual double getBucketSize( size_t index = 0 ) const = 0;
00107 
00108     /**
00109      * Returns the actual interval associated with the given index. The interval is open, meaning that
00110      * getIntervalForIndex( i ).second == getIntervalForIndex( i + 1 ).first but does not belong anymore to the interval itself but every value
00111      * smaller than getIntervalForIndex( i ).second.
00112      *
00113      * \param index the intex
00114      *
00115      * \return the open interval.
00116      */
00117     virtual std::pair< double, double > getIntervalForIndex( size_t index ) const = 0;
00118 
00119 protected:
00120     /**
00121      * The smallest value
00122      */
00123     double m_minimum;
00124 
00125     /**
00126      * The biggest value
00127      */
00128     double m_maximum;
00129 
00130     /**
00131      * The number of buckets.
00132      */
00133     double m_nbBuckets;
00134 
00135 private:
00136 };
00137 
00138 #endif  // WHISTOGRAM_H