Class used to store data and make an histogram of the data frequency. More...
#include "histogram.h"
Public Member Functions | |
Histogram () | |
Histogram (double binWidth) | |
Constructor. | |
void | AddValue (double value) |
Add a value to the histogram. | |
void | Clear () |
Clear the histogram content. | |
uint32_t | GetBinCount (uint32_t index) const |
Get the number of data added to the bin. | |
double | GetBinEnd (uint32_t index) const |
Returns the bin end, i.e., (index+1)*binWidth. | |
double | GetBinStart (uint32_t index) const |
Returns the bin start, i.e., index*binWidth. | |
double | GetBinWidth (uint32_t index) const |
Returns the bin width. | |
uint32_t | GetNBins () const |
Returns the number of bins in the histogram. | |
void | SerializeToXmlStream (std::ostream &os, uint16_t indent, std::string elementName) const |
Serializes the results to an std::ostream in XML format. | |
void | SetDefaultBinWidth (double binWidth) |
Set the bin width. | |
Private Attributes | |
double | m_binWidth |
Bin width. | |
std::vector< uint32_t > | m_histogram |
Histogram data. | |
Class used to store data and make an histogram of the data frequency.
Data are grouped in "bins", i.e., intervals. Each value is assigned to the bin according to the following formula: floor(value/binWidth). Hence, bin i groups the data from [i*binWidth, (i+1)binWidth).
This class only handles positive bins, i.e., it does not handles negative data.
Definition at line 34 of file histogram.h.
ns3::Histogram::Histogram | ( | double | binWidth | ) |
Constructor.
binWidth | width of the histogram "bin". |
Definition at line 90 of file histogram.cc.
References m_binWidth.
ns3::Histogram::Histogram | ( | ) |
Definition at line 95 of file histogram.cc.
References DEFAULT_BIN_WIDTH, and m_binWidth.
void ns3::Histogram::AddValue | ( | double | value | ) |
Add a value to the histogram.
value | the value to add |
Definition at line 70 of file histogram.cc.
References m_binWidth, m_histogram, and NS_LOG_DEBUG.
Referenced by HistogramTestCase::DoRun(), ns3::FlowMonitor::ReportLastRx(), and RunBothModes().
void ns3::Histogram::Clear | ( | ) |
Get the number of data added to the bin.
index | the bin index |
Definition at line 63 of file histogram.cc.
References m_histogram, and NS_ASSERT.
Referenced by HistogramTestCase::DoRun(), and RunBothModes().
Returns the bin end, i.e., (index+1)*binWidth.
index | the bin index |
Definition at line 44 of file histogram.cc.
References m_binWidth.
Returns the bin start, i.e., index*binWidth.
index | the bin index |
Definition at line 38 of file histogram.cc.
References m_binWidth.
Referenced by HistogramTestCase::DoRun(), and RunBothModes().
Returns the bin width.
Note that all the bins have the same width.
index | the bin index |
Definition at line 50 of file histogram.cc.
References m_binWidth.
Referenced by HistogramTestCase::DoRun(), and RunBothModes().
uint32_t ns3::Histogram::GetNBins | ( | ) | const |
Returns the number of bins in the histogram.
Definition at line 32 of file histogram.cc.
References m_histogram.
Referenced by HistogramTestCase::DoRun(), and RunBothModes().
void ns3::Histogram::SerializeToXmlStream | ( | std::ostream & | os, |
uint16_t | indent, | ||
std::string | elementName ) const |
Serializes the results to an std::ostream in XML format.
os | the output stream |
indent | number of spaces to use as base indentation level |
elementName | name of the element to serialize. |
Definition at line 101 of file histogram.cc.
References m_binWidth, and m_histogram.
void ns3::Histogram::SetDefaultBinWidth | ( | double | binWidth | ) |
Set the bin width.
Note that you can change the bin width only if the histogram is empty.
binWidth | the bin width |
Definition at line 56 of file histogram.cc.
References m_binWidth, m_histogram, and NS_ASSERT.
Referenced by ns3::FlowMonitor::GetStatsForFlow().
|
private |
Bin width.
Definition at line 109 of file histogram.h.
Referenced by Histogram(), Histogram(), AddValue(), GetBinEnd(), GetBinStart(), GetBinWidth(), SerializeToXmlStream(), and SetDefaultBinWidth().
|
private |
Histogram data.
Definition at line 108 of file histogram.h.
Referenced by AddValue(), Clear(), GetBinCount(), GetNBins(), SerializeToXmlStream(), and SetDefaultBinWidth().