#include <histogram.h>
Note that this implementation sorts and consolidates bins lazily, meaning that there can be bins with duplicate indices in the internal structure. However, the public interface behaves as though the internal data is always sorted and consolidated, so there is no need to worry about duplicate bins or unsorted bins when accessing elements using any of the public methods.
Public Member Functions | |
Histogram () | |
~Histogram () | |
Bin * | AddBin (const Bin &new_bin) |
Adds a copy of <new_bin> to the histogram. | |
void | SortBins () const |
Sorts and consolidates bins. | |
int | GetNumBins () const |
Gets the total number of bins with unique index. | |
const Bin * | GetBin (int ii) |
Assuming the Bins are sorted, gets the <ii>th bin in the ordering. | |
const Bin * | GetBin (const LargeIndex &index) |
Gets the bin with the given index. | |
const Bin * | GetBin (const LargeIndex &index, int finger) |
Gets the Bin with the given index after the <finger>th Bin. | |
Static Public Member Functions | |
static double | ComputeIntersection (Histogram *first, Histogram *second) |
Compute the histogram intersection. | |
static void | WriteToStream (ostream &output_stream, const vector< Histogram * > &histograms) |
Write a vector of Histograms to a stream. | |
static void | WriteSingleHistogramToStream (ostream &output_stream, Histogram *h) |
Write a single Histogram to a stream. | |
static vector< Histogram * > | ReadFromStream (istream &input_stream) |
Read a vector of Histograms from a stream. | |
static Histogram * | ReadSingleHistogramFromStream (istream &input_stream) |
Read a single Histogram from a stream. |
Histogram | ( | ) |
~Histogram | ( | ) |
Adds a copy of <new_bin> to the histogram.
By "adding a bin", we mean looking for the Bin in this histogram that has the same index (the LargeIndex identifier) as <new_bin> and increasing the count by that much. It also will set the size of the bin to be the maximum of the two bin sizes. The parent, child, and sibling pointers of <new_bin> are completely ignored.
void SortBins | ( | ) | const |
Sorts and consolidates bins.
It is not necessary to call this manually, as all of the sorting and consolidation is done automatically (lazily). However, for performance reasons, you may call this manually.
int GetNumBins | ( | ) | const |
Gets the total number of bins with unique index.
const Bin * GetBin | ( | int | ii | ) |
Assuming the Bins are sorted, gets the <ii>th bin in the ordering.
The Bins are sorted in order of increasing index.
const Bin * GetBin | ( | const LargeIndex & | index | ) |
Gets the bin with the given index.
This will return NULL if no such Bin is found.
const Bin * GetBin | ( | const LargeIndex & | index, | |
int | finger | |||
) |
Compute the histogram intersection.
void WriteToStream | ( | ostream & | output_stream, | |
const vector< Histogram * > & | histograms | |||
) | [static] |
Write a vector of Histograms to a stream.
The output format is as follows:
void WriteSingleHistogramToStream | ( | ostream & | output_stream, | |
Histogram * | h | |||
) | [static] |
Write a single Histogram to a stream.
The output format is as follows:
The bins are sorted before they are written. They are sorted in order of increasing index.
vector< Histogram * > ReadFromStream | ( | istream & | input_stream | ) | [static] |
Read a vector of Histograms from a stream.
This function allocates new memory for the histograms. The caller is responsible for freeing it. For the file format, see WriteToStream.
Histogram * ReadSingleHistogramFromStream | ( | istream & | input_stream | ) | [static] |
Read a single Histogram from a stream.
This function allocates new memory for the histogram. The caller is responsible for freeing it. For the file format, see ReadFromStream.