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