WHistogram.h 3.98 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
#include "WExportCommon.h"
31

32
/**
33 34
 * 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.
35
 */
36
class OWCOMMON_EXPORT WHistogram // NOLINT
37 38 39
{
public:
    /**
40
     * Default constructor. Creates an empty histogram covering the specified min and max values with the specified number of buckets.
41
     *
42 43 44
     * \param min the smallest value
     * \param max the largest value
     * \param buckets the number of buckets
45
     */
46 47 48 49 50 51 52 53
    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 );
54 55 56 57

    /**
     * Default destructor.
     */
58
    virtual ~WHistogram();
59 60

    /**
61 62 63
     * 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.
64
     *
65
     * \return elements in the bucket.
66
     */
67
    virtual size_t operator[]( size_t index ) const = 0;
68 69

    /**
70 71 72
     * 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.
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 89 90 91 92 93
     * \return minimum
     */
    virtual double getMinimum() const;

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

99 100 101 102 103 104 105 106
    /**
     * 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;
107 108

    /**
109 110 111 112 113 114 115
     * 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.
116
     */
117 118 119
    virtual std::pair< double, double > getIntervalForIndex( size_t index ) const = 0;

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 135 136
    double m_nbBuckets;

private:
137 138 139
};

#endif  // WHISTOGRAM_H