WHistogram.h 3.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WHISTOGRAM_H
#define WHISTOGRAM_H

28
#include <utility>
29 30

/**
31 32
 * Container which associate values with (uniform width) bins (aka intervals or buckets). This class implements the abstract interface and
 * therefore builds the base class for all histogram classes. The interface also allows programming histogram of different bucket sizes.
33 34 35 36 37
 */
class WHistogram
{
public:
    /**
38
     * Default constructor. Creates an empty histogram covering the specified min and max values with the specified number of buckets.
39
     *
40 41 42
     * \param min the smallest value
     * \param max the largest value
     * \param buckets the number of buckets
43
     */
44 45 46 47 48 49 50 51
    WHistogram( double min, double max, size_t buckets = 1000 );

    /**
     * Copy constructor. Creates a deep copy of the specified histogram.
     *
     * \param hist the histogram to copy.
     */
    WHistogram( const WHistogram& hist );
52 53 54 55

    /**
     * Default destructor.
     */
56
    virtual ~WHistogram();
57 58

    /**
59 60 61
     * Get the count of the specified bucket.
     *
     * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
62
     *
63
     * \return elements in the bucket.
64
     */
65
    virtual size_t operator[]( size_t index ) const = 0;
66 67

    /**
68 69 70
     * Get the count of the specified bucket. Testing if the position is valid.
     *
     * \param index which buckets count is to be returned; starts with 0 which is the bucket containing the smallest values.
71
     *
72
     * \return elements in the bucket
73
     */
74
    virtual size_t at( size_t index ) const = 0;
75 76

    /**
77
     * Returns the number of buckets in the histogram with the actual mapping.
78
     *
79
     * \return number of buckets
80
     */
81
    virtual size_t size() const;
82 83

    /**
84
     * Returns the minimum value.
85
     *
86 87 88 89 90 91
     * \return minimum
     */
    virtual double getMinimum() const;

    /**
     * Returns the maximum value.
92
     *
93
     * \return maximum
94
     */
95
    virtual double getMaximum() const;
96

97 98 99 100 101 102 103 104
    /**
     * Return the size of one specific bucket.
     *
     * \param index the width for this bucket is queried.
     *
     * \return the size of a bucket.
     */
    virtual double getBucketSize( size_t index = 0 ) const = 0;
105 106

    /**
107 108 109 110 111 112 113
     * Returns the actual interval associated with the given index. The interval is open, meaning that
     * getIntervalForIndex( i ).second == getIntervalForIndex( i + 1 ).first but does not belong anymore to the interval itself but every value
     * smaller than getIntervalForIndex( i ).second.
     *
     * \param index the intex
     *
     * \return the open interval.
114
     */
115 116 117
    virtual std::pair< double, double > getIntervalForIndex( size_t index ) const = 0;

protected:
118 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 133 134
    double m_nbBuckets;

private:
135 136 137
};

#endif  // WHISTOGRAM_H