Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenWalnut Core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
767467ae
Commit
767467ae
authored
Aug 03, 2010
by
Sebastian Eichelbaum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CHANGE] - renamed WHistogram in dataStructures to better match its real purpose.
[STYLE] - improved style and spelling
parent
df9d1a6f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
222 additions
and
267 deletions
+222
-267
src/dataHandler/datastructures/WHistogram.h
src/dataHandler/datastructures/WHistogram.h
+0
-203
src/dataHandler/datastructures/WValueSetHistogram.cpp
src/dataHandler/datastructures/WValueSetHistogram.cpp
+21
-64
src/dataHandler/datastructures/WValueSetHistogram.h
src/dataHandler/datastructures/WValueSetHistogram.h
+201
-0
No files found.
src/dataHandler/datastructures/WHistogram.h
deleted
100644 → 0
View file @
df9d1a6f
//---------------------------------------------------------------------------
//
// 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
#include <map>
#include <list>
#include <utility>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_array.hpp>
#include <boost/shared_array.hpp>
#include "../WValueSet.h"
/**
* Used to track (later: display) the occurrence frequencies of values in a value set.
**/
class
WHistogram
{
private:
/**
* The smalest value in the ValueSet
**/
double
m_minimum
;
/**
* The biggest value in the ValueSet
**/
double
m_maximum
;
/**
* Size of one bucket in the initial histogram.
**/
double
m_bucketSize
;
/**
* Pointer to all initial buckets of the histogram.
**/
boost
::
shared_array
<
unsigned
int
>
m_initialBuckets
;
/**
* Number of buckets in the initial histogram.
**/
unsigned
int
m_nInitialBuckets
;
/**
* Pointer to all the buckets in the mapped histogram.
**/
boost
::
scoped_array
<
unsigned
int
>
m_mappedBuckets
;
/**
* Tracks the number of a buckets in the mapped histogram.
**/
unsigned
int
m_nMappedBuckets
;
/**
* To calculate the new buckets
*
* \param intervalSize the size of one bucket
**/
void
calculateMapping
(
double
intervalSize
);
/**
* increment the value by one, contains the logic to find the element place in the array.
* Should only be used in the constructor ie. while iterating over WValueSet.
*
* \param value value to increment
**/
void
increment
(
double
value
);
protected:
/**
* Return the initial buckets.
*
* \return m_initialBuckets
**/
boost
::
shared_array
<
unsigned
int
>
getInitialBuckets
()
const
;
/**
* Return the number of initial buckets.
*
* \return m_nInitialBuckets
**/
unsigned
int
getNInitialBuckets
()
const
;
/**
* Return the size of one initial bucket.
*
* \return m_bucketSize
**/
double
getBucketSize
()
const
;
public:
/**
* Constructor.
*
* \param valueSet source of the data for the histogram
**/
explicit
WHistogram
(
boost
::
shared_ptr
<
WValueSetBase
>
valueSet
);
/**
* Constructor.
*
* \param valueSet source of the data for the histogram
**/
explicit
WHistogram
(
const
WValueSetBase
&
valueSet
);
/**
* Copy constructor. If another interval size is given setInterval() is called and a
* the mapped histogram is calculated.
*
* \param histogram another WHisogram
* \param intervalSize the size of one bucket in the mapped histogram
**/
explicit
WHistogram
(
const
WHistogram
&
histogram
,
double
intervalSize
=
0.0
);
/**
* Destructor.
**/
~
WHistogram
();
/**
* Set the new intervall size.
*
* \param intervalSize size of the interval for each mapped bucket.
*
* \return size of the new (mapped) histogram.
**/
unsigned
int
setInterval
(
double
intervalSize
);
/**
* Get the size of the bucket.
*
* \param index which buckets size is to be returned, starts with 0 which is the bucket
* containing the smalest values.
*
* \return elements in the bucket.
**/
unsigned
int
operator
[](
unsigned
int
index
);
/**
* Get the size of the bucket. Testing if the position is valid.
*
* \param index which buckets size is to be returned, starts with 0 which is the bar with
* the smalest values
*
* \return elements in the bucket
**/
unsigned
int
at
(
unsigned
int
index
);
/**
* Returns the number of bars in the histogram with the actual mapping.
*
* \return number of buckets
**/
unsigned
int
size
()
const
;
/**
* Retruns the minimum value in the value set.
*
* \return minimum
**/
double
getMin
()
const
;
/**
* Retruns the maximum value in the value set.
*
* \return maximum
**/
double
getMax
()
const
;
/**
* to test if the histogram works
**/
void
test
();
};
#endif // WHISTOGRAM_H
src/dataHandler/datastructures/WHistogram.cpp
→
src/dataHandler/datastructures/W
ValueSet
Histogram.cpp
View file @
767467ae
...
...
@@ -22,16 +22,14 @@
//
//---------------------------------------------------------------------------
#include <cmath> // test() -> log()
#include <cstring> // memset()
#include <iostream> // test() -> std::cout
#include "../../common/WAssert.h"
#include "../../common/WLimits.h"
#include "WHistogram.h"
#include "W
ValueSet
Histogram.h"
W
Histogram
::
W
Histogram
(
boost
::
shared_ptr
<
WValueSetBase
>
valueSet
)
W
ValueSetHistogram
::
WValueSet
Histogram
(
boost
::
shared_ptr
<
WValueSetBase
>
valueSet
)
{
// calculate min max
m_minimum
=
wlimits
::
MAX_DOUBLE
;
...
...
@@ -71,7 +69,7 @@ WHistogram::WHistogram( boost::shared_ptr< WValueSetBase > valueSet )
}
}
W
Histogram
::
W
Histogram
(
const
WValueSetBase
&
valueSet
)
W
ValueSetHistogram
::
WValueSet
Histogram
(
const
WValueSetBase
&
valueSet
)
{
// calculate min max
m_minimum
=
wlimits
::
MAX_DOUBLE
;
...
...
@@ -111,7 +109,7 @@ WHistogram::WHistogram( const WValueSetBase& valueSet )
}
}
W
Histogram
::
WHistogram
(
const
W
Histogram
&
histogram
,
double
intervalSize
)
W
ValueSetHistogram
::
WValueSetHistogram
(
const
WValueSet
Histogram
&
histogram
,
double
intervalSize
)
{
// copy constructor
m_nInitialBuckets
=
histogram
.
getNInitialBuckets
();
...
...
@@ -125,38 +123,38 @@ WHistogram::WHistogram( const WHistogram& histogram, double intervalSize )
if
(
intervalSize
!=
0.0
)
{
WAssert
(
intervalSize
>
0.0
,
"W
Histogram::W
Histogram : intervalSize has to be greater then zero."
);
WAssert
(
intervalSize
>
0.0
,
"W
ValueSetHistogram::WValueSet
Histogram : intervalSize has to be greater then zero."
);
calculateMapping
(
intervalSize
);
}
}
W
Histogram
::~
W
Histogram
()
W
ValueSetHistogram
::~
WValueSet
Histogram
()
{
}
boost
::
shared_array
<
unsigned
int
>
WHistogram
::
getInitialBuckets
()
const
boost
::
shared_array
<
unsigned
int
>
W
ValueSet
Histogram
::
getInitialBuckets
()
const
{
return
m_initialBuckets
;
}
unsigned
int
WHistogram
::
getNInitialBuckets
()
const
unsigned
int
W
ValueSet
Histogram
::
getNInitialBuckets
()
const
{
return
m_nInitialBuckets
;
}
double
WHistogram
::
getBucketSize
()
const
double
W
ValueSet
Histogram
::
getBucketSize
()
const
{
return
m_bucketSize
;
}
void
WHistogram
::
increment
(
double
value
)
void
W
ValueSet
Histogram
::
increment
(
double
value
)
{
WAssert
(
m_bucketSize
>
0.0
,
"WHistogram::increment() : m_bucketSize to small."
);
WAssert
(
m_bucketSize
>
0.0
,
"W
ValueSet
Histogram::increment() : m_bucketSize to small."
);
unsigned
int
index
=
static_cast
<
unsigned
int
>
(
value
/
m_bucketSize
);
m_initialBuckets
[
index
]
++
;
}
unsigned
int
WHistogram
::
setInterval
(
double
intervalSize
)
unsigned
int
W
ValueSet
Histogram
::
setInterval
(
double
intervalSize
)
{
if
(
m_bucketSize
==
intervalSize
)
{
...
...
@@ -173,10 +171,10 @@ unsigned int WHistogram::setInterval( double intervalSize )
return
m_nMappedBuckets
;
}
void
WHistogram
::
calculateMapping
(
double
intervalSize
)
void
W
ValueSet
Histogram
::
calculateMapping
(
double
intervalSize
)
{
unsigned
int
ratio
=
static_cast
<
unsigned
int
>
(
intervalSize
/
m_bucketSize
);
WAssert
(
ratio
>
1
,
"WHistogram::calculateMapping() : intervalSize has to be greater then the original size."
);
WAssert
(
ratio
>
1
,
"W
ValueSet
Histogram::calculateMapping() : intervalSize has to be greater then the original size."
);
// number of elements in the new mapped histogram = division + (round up)
m_nMappedBuckets
=
m_nInitialBuckets
/
ratio
+
(
m_nInitialBuckets
%
ratio
>
0
?
1
:
0
);
...
...
@@ -201,7 +199,7 @@ void WHistogram::calculateMapping( double intervalSize )
}
}
unsigned
int
WHistogram
::
operator
[](
unsigned
int
index
)
unsigned
int
W
ValueSet
Histogram
::
operator
[](
unsigned
int
index
)
{
unsigned
int
value
=
0
;
if
(
m_mappedBuckets
)
...
...
@@ -215,75 +213,34 @@ unsigned int WHistogram::operator[]( unsigned int index )
return
value
;
}
unsigned
int
WHistogram
::
at
(
unsigned
int
index
)
unsigned
int
W
ValueSet
Histogram
::
at
(
unsigned
int
index
)
{
unsigned
int
value
=
0
;
if
(
m_mappedBuckets
)
{
WAssert
(
index
<
m_nMappedBuckets
,
"WHistogram::at() : index out of range."
);
WAssert
(
index
<
m_nMappedBuckets
,
"W
ValueSet
Histogram::at() : index out of range."
);
value
=
m_mappedBuckets
[
index
];
}
else
{
WAssert
(
index
<
m_nInitialBuckets
,
"WHistogram::at() : index out of range."
);
WAssert
(
index
<
m_nInitialBuckets
,
"W
ValueSet
Histogram::at() : index out of range."
);
value
=
m_initialBuckets
[
index
];
}
return
value
;
}
unsigned
int
WHistogram
::
size
()
const
unsigned
int
W
ValueSet
Histogram
::
size
()
const
{
return
(
m_mappedBuckets
?
m_nMappedBuckets
:
m_nInitialBuckets
);
}
double
WHistogram
::
getMin
()
const
double
W
ValueSet
Histogram
::
getMin
()
const
{
return
m_minimum
;
}
double
WHistogram
::
getMax
()
const
double
W
ValueSet
Histogram
::
getMax
()
const
{
return
m_maximum
;
}
void
WHistogram
::
test
()
{
unsigned
int
*
ptr
;
unsigned
int
histSize
;
if
(
m_mappedBuckets
)
{
ptr
=
m_mappedBuckets
.
get
();
histSize
=
m_nMappedBuckets
;
}
else
{
ptr
=
m_initialBuckets
.
get
();
histSize
=
m_nInitialBuckets
;
}
for
(
unsigned
int
y
=
10
;
y
!=
0
;
--
y
)
{
std
::
cout
<<
"|"
;
unsigned
int
*
h_ptr
=
ptr
;
for
(
unsigned
int
x
=
0
;
x
!=
histSize
;
++
x
)
{
if
(
log
(
static_cast
<
double
>
(
*
h_ptr
)
)
>
static_cast
<
double
>
(
(
y
-
1
)
*
2
)
)
{
std
::
cout
<<
" #"
;
}
else
{
std
::
cout
<<
" "
;
}
h_ptr
++
;
}
std
::
cout
<<
" |
\n
"
;
}
std
::
cout
<<
"-"
;
for
(
unsigned
int
i
=
0
;
i
!=
histSize
;
++
i
)
{
std
::
cout
<<
"--"
;
}
std
::
cout
<<
"--
\n
"
;
}
src/dataHandler/datastructures/WValueSetHistogram.h
0 → 100644
View file @
767467ae
//---------------------------------------------------------------------------
//
// 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 WVALUESETHISTOGRAM_H
#define WVALUESETHISTOGRAM_H
#include <map>
#include <list>
#include <utility>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_array.hpp>
#include <boost/shared_array.hpp>
#include "../WValueSet.h"
/**
* Used to find the occurrence frequencies of values in a value set. It implements a classical histogram but allows easy modification of bucket
* sizes without unnecessary recalculation of the whole histogram.
*
* \note This histogram is different from from WValueSetHistogram which is a generic histogram class.
*/
class
WValueSetHistogram
{
public:
/**
* Constructor. Creates the histogram for the specified value set.
*
* \param valueSet source of the data for the histogram
*/
explicit
WValueSetHistogram
(
boost
::
shared_ptr
<
WValueSetBase
>
valueSet
);
/**
* Constructor. Creates the histogram for the specified value set.
*
* \param valueSet source of the data for the histogram
*/
explicit
WValueSetHistogram
(
const
WValueSetBase
&
valueSet
);
/**
* Copy constructor. If another interval size is given setInterval() is called and
* the mapped histogram is calculated.
*
* \param histogram another WValueSetHistogram
* \param intervalSize the size of one bucket in the mapped histogram
*/
explicit
WValueSetHistogram
(
const
WValueSetHistogram
&
histogram
,
double
intervalSize
=
0.0
);
/**
* Destructor.
*/
~
WValueSetHistogram
();
/**
* Set the new interval size.
*
* \param intervalSize size of the interval for each mapped bucket.
*
* \return size of the new (mapped) histogram.
*/
unsigned
int
setInterval
(
double
intervalSize
);
/**
* Get the size of the bucket.
*
* \param index which buckets size is to be returned, starts with 0 which is the bucket
* containing the smallest values.
*
* \return elements in the bucket.
*/
unsigned
int
operator
[](
unsigned
int
index
);
/**
* Get the size of the bucket. Testing if the position is valid.
*
* \param index which buckets size is to be returned, starts with 0 which is the bar with
* the smallest values
*
* \return elements in the bucket
*/
unsigned
int
at
(
unsigned
int
index
);
/**
* Returns the number of bars in the histogram with the actual mapping.
*
* \return number of buckets
*/
unsigned
int
size
()
const
;
/**
* Returns the minimum value in the value set.
*
* \return minimum
*/
double
getMin
()
const
;
/**
* Returns the maximum value in the value set.
*
* \return maximum
*/
double
getMax
()
const
;
protected:
/**
* Return the initial buckets.
*
* \return m_initialBuckets
*/
boost
::
shared_array
<
unsigned
int
>
getInitialBuckets
()
const
;
/**
* Return the number of initial buckets.
*
* \return m_nInitialBuckets
*/
unsigned
int
getNInitialBuckets
()
const
;
/**
* Return the size of one initial bucket.
*
* \return m_bucketSize
*/
double
getBucketSize
()
const
;
private:
/**
* The smallest value in the ValueSet
*/
double
m_minimum
;
/**
* The biggest value in the ValueSet
*/
double
m_maximum
;
/**
* Size of one bucket in the initial histogram.
*/
double
m_bucketSize
;
/**
* Pointer to all initial buckets of the histogram.
*/
boost
::
shared_array
<
unsigned
int
>
m_initialBuckets
;
/**
* Number of buckets in the initial histogram.
*/
unsigned
int
m_nInitialBuckets
;
/**
* Pointer to all the buckets in the mapped histogram.
*/
boost
::
scoped_array
<
unsigned
int
>
m_mappedBuckets
;
/**
* Tracks the number of a buckets in the mapped histogram.
*/
unsigned
int
m_nMappedBuckets
;
/**
* To calculate the new buckets
*
* \param intervalSize the size of one bucket
*/
void
calculateMapping
(
double
intervalSize
);
/**
* increment the value by one, contains the logic to find the element place in the array.
* Should only be used in the constructor i.e. while iterating over WValueSet.
*
* \param value value to increment
*/
void
increment
(
double
value
);
};
#endif // WVALUESETHISTOGRAM_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment