A Discrete-Event Network Simulator
API
ns3::Histogram Class Reference

Class used to store data and make an histogram of the data frequency. More...

#include "histogram.h"

+ Collaboration diagram for ns3::Histogram:

Public Member Functions

 Histogram ()
 
 Histogram (double binWidth)
 Constructor. More...
 
void AddValue (double value)
 Add a value to the histogram. More...
 
void Clear ()
 Clear the histogram content. More...
 
uint32_t GetBinCount (uint32_t index) const
 Get the number of data added to the bin. More...
 
double GetBinEnd (uint32_t index) const
 Returns the bin end, i.e., (index+1)*binWidth. More...
 
double GetBinStart (uint32_t index) const
 Returns the bin start, i.e., index*binWidth. More...
 
double GetBinWidth (uint32_t index) const
 Returns the bin width. More...
 
uint32_t GetNBins () const
 Returns the number of bins in the histogram. More...
 
void SerializeToXmlStream (std::ostream &os, uint16_t indent, std::string elementName) const
 Serializes the results to an std::ostream in XML format. More...
 
void SetDefaultBinWidth (double binWidth)
 Set the bin width. More...
 

Private Attributes

double m_binWidth
 Bin width. More...
 
std::vector< uint32_t > m_histogram
 Histogram data. More...
 

Detailed Description

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.

Todo:
Add support for negative data.
Todo:
Add method(s) to estimate parameters from the histogram, see http://www.dspguide.com/ch2/4.htm

Definition at line 45 of file histogram.h.

Constructor & Destructor Documentation

◆ Histogram() [1/2]

ns3::Histogram::Histogram ( double  binWidth)

Constructor.

Parameters
binWidthwidth of the histogram "bin".

Definition at line 101 of file histogram.cc.

References m_binWidth.

◆ Histogram() [2/2]

ns3::Histogram::Histogram ( )

Definition at line 106 of file histogram.cc.

References DEFAULT_BIN_WIDTH, and m_binWidth.

Member Function Documentation

◆ AddValue()

void ns3::Histogram::AddValue ( double  value)

Add a value to the histogram.

Parameters
valuethe value to add

Definition at line 81 of file histogram.cc.

References m_binWidth, m_histogram, and NS_LOG_DEBUG.

Referenced by HistogramTestCase::DoRun(), ns3::FlowMonitor::ReportLastRx(), and RunBothModes().

+ Here is the caller graph for this function:

◆ Clear()

void ns3::Histogram::Clear ( )

Clear the histogram content.

Definition at line 96 of file histogram.cc.

References m_histogram.

◆ GetBinCount()

uint32_t ns3::Histogram::GetBinCount ( uint32_t  index) const

Get the number of data added to the bin.

Parameters
indexthe bin index
Returns
the number of data added to the bin

Definition at line 74 of file histogram.cc.

References m_histogram, and NS_ASSERT.

Referenced by HistogramTestCase::DoRun(), and RunBothModes().

+ Here is the caller graph for this function:

◆ GetBinEnd()

double ns3::Histogram::GetBinEnd ( uint32_t  index) const

Returns the bin end, i.e., (index+1)*binWidth.

Parameters
indexthe bin index
Returns
the bin start

Definition at line 55 of file histogram.cc.

References m_binWidth.

◆ GetBinStart()

double ns3::Histogram::GetBinStart ( uint32_t  index) const

Returns the bin start, i.e., index*binWidth.

Parameters
indexthe bin index
Returns
the bin start

Definition at line 49 of file histogram.cc.

References m_binWidth.

Referenced by HistogramTestCase::DoRun(), and RunBothModes().

+ Here is the caller graph for this function:

◆ GetBinWidth()

double ns3::Histogram::GetBinWidth ( uint32_t  index) const

Returns the bin width.

Note that all the bins have the same width.

Parameters
indexthe bin index
Returns
the bin width

Definition at line 61 of file histogram.cc.

References m_binWidth.

Referenced by HistogramTestCase::DoRun(), and RunBothModes().

+ Here is the caller graph for this function:

◆ GetNBins()

uint32_t ns3::Histogram::GetNBins ( ) const

Returns the number of bins in the histogram.

Returns
the number of bins in the histogram

Definition at line 43 of file histogram.cc.

References m_histogram.

Referenced by HistogramTestCase::DoRun(), and RunBothModes().

+ Here is the caller graph for this function:

◆ SerializeToXmlStream()

void ns3::Histogram::SerializeToXmlStream ( std::ostream &  os,
uint16_t  indent,
std::string  elementName 
) const

Serializes the results to an std::ostream in XML format.

Parameters
osthe output stream
indentnumber of spaces to use as base indentation level
elementNamename of the element to serialize.

Definition at line 112 of file histogram.cc.

References m_binWidth, and m_histogram.

◆ SetDefaultBinWidth()

void ns3::Histogram::SetDefaultBinWidth ( double  binWidth)

Set the bin width.

Note that you can change the bin width only if the histogram is empty.

Parameters
binWidththe bin width

Definition at line 67 of file histogram.cc.

References m_binWidth, m_histogram, and NS_ASSERT.

Referenced by ns3::FlowMonitor::GetStatsForFlow().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_binWidth

double ns3::Histogram::m_binWidth
private

◆ m_histogram

std::vector<uint32_t> ns3::Histogram::m_histogram
private

The documentation for this class was generated from the following files: