#include <multi-resolution-histogram.h>
A wrapper class around Tree. This data structure encapsulates a Tree of Bin objects, where a Bin just contains a weight (size) and a count.
Public Member Functions | |
MultiResolutionHistogram () | |
int | GetNumLevels () const |
int | GetNumBins () const |
Bin * | GetBin (LargeIndex index) |
Get a pointer to the bin with the specified index. | |
Bin * | GetBin (LargeIndex index, Bin *finger) |
Get a pointer to the bin with specified index. | |
Bin * | GetRootBin () |
Get a pointer to the root bin. | |
Bin *const | GetRootBin () const |
Bin * | AddBin (const Bin &new_bin) |
Insert a copy of the given bin into the tree. | |
Bin * | AddBin (const Bin &new_bin, Bin *finger) |
Insert a copy of the given bin into the tree. | |
void | DeleteBin (Bin *finger) |
Remove a bin, and all of its children, from the pyramid. | |
Static Public Member Functions | |
static vector< MultiResolutionHistogram * > | ReadFromStream (istream &input_stream) |
Reads all the MultiResolutionHistograms in a stream. | |
static vector< MultiResolutionHistogram * > | ReadFromFile (const char *filename) |
Reads all the MultiResolutionHistograms in a file. | |
static vector< MultiResolutionHistogram * > | ReadSelectionFromStream (istream &input_stream, int start, int selection_size) |
Reads some MultiResolutionHistograms from a stream. | |
static vector< MultiResolutionHistogram * > | ReadSelectionFromFile (const char *filename, int start, int selection_size) |
Reads some MultiResolutionHistograms from a file. | |
static void | WriteToStream (ostream &output_stream, const vector< MultiResolutionHistogram * > &hists) |
Writes all of the MultiResolutionHistograms to a stream. | |
static void | WriteToFile (const char *filename, const vector< MultiResolutionHistogram * > &hists) |
Writes all of the MultiResolutionHistograms to a file. | |
static MultiResolutionHistogram * | ReadSingleHistogramFromStream (istream &input_stream) |
Reads just one histogram from a stream. | |
static void | IgnoreSingleHistogramFromStream (istream &input_stream) |
Throws out one histogram's worth of data from the stream. | |
static void | WriteSingleHistogramToStream (ostream &output_stream, const MultiResolutionHistogram *h) |
Write just one histogram to a stream. |
MultiResolutionHistogram | ( | ) | [inline] |
int GetNumLevels | ( | ) | const |
int GetNumBins | ( | ) | const |
Bin * GetBin | ( | LargeIndex | index | ) |
Get a pointer to the bin with the specified index.
Returns NULL if the bin is not found.
Bin * GetBin | ( | LargeIndex | index, | |
Bin * | finger | |||
) |
Get a pointer to the bin with specified index.
Same as GetBin(LargeIndex), but localizes the search to the subtree given by finger. Returns NULL if there is no such Bin in a subtree of <finger>.
Bin * GetRootBin | ( | ) |
Get a pointer to the root bin.
Bin *const GetRootBin | ( | ) | const |
Insert a copy of the given bin into the tree.
Returns a pointer to the newly-added bin in the tree. This function completely ignores any parent/child/sibling pointers in <new_bin>.
This function requires the parent bin to exist. It will not create new bins along the way (it will abort if there is no parent bin, i.e., a bin whose index is a prefix of that of <new_bin> and whose index size is exactly 1 less than the new bin's index size. The insertion happens such that the sibling relationships remain sorted by index.
If there is already is a bin with the given index, we add the counts and keep the larger of the two sizes. This applies to the root bin as well.
Insert a copy of the given bin into the tree.
Same as AddBin(const Bin&), except it starts the search for the bin at <finger>. A parent to <new_bin> must already exist, and must be present in a sub-branch of <finger> (it may also be <finger>).
void DeleteBin | ( | Bin * | finger | ) |
Remove a bin, and all of its children, from the pyramid.
vector< MultiResolutionHistogram * > ReadFromStream | ( | istream & | input_stream | ) | [static] |
Reads all the MultiResolutionHistograms in a stream.
File format:
Aborts if input_stream cannot be read.
vector< MultiResolutionHistogram * > ReadFromFile | ( | const char * | filename | ) | [static] |
vector< MultiResolutionHistogram * > ReadSelectionFromStream | ( | istream & | input_stream, | |
int | start, | |||
int | selection_size | |||
) | [static] |
Reads some MultiResolutionHistograms from a stream.
<start> specifies the index of the first histogram to read in the stream of data. If <selection_size> is large enough so that this would want to read past the end of the file, ReadSelectionFromStream will just stop reading. Observe that you will need to adjust indices (i.e., if you choose to read Y histograms starting from index X, then result[0] will be the 6th histogram, as opposed to this[5]).
Aborts if the input_stream cannot be read.
vector< MultiResolutionHistogram * > ReadSelectionFromFile | ( | const char * | filename, | |
int | start, | |||
int | selection_size | |||
) | [static] |
void WriteToStream | ( | ostream & | output_stream, | |
const vector< MultiResolutionHistogram * > & | hists | |||
) | [static] |
Writes all of the MultiResolutionHistograms to a stream.
Aborts if the stream is bad. See ReadFromStream for the file format.
void WriteToFile | ( | const char * | filename, | |
const vector< MultiResolutionHistogram * > & | hists | |||
) | [static] |
MultiResolutionHistogram * ReadSingleHistogramFromStream | ( | istream & | input_stream | ) | [static] |
Reads just one histogram from a stream.
File format:
The ordering of the bins is a depth-first traversal of the tree.
Aborts if the stream is bad.
void IgnoreSingleHistogramFromStream | ( | istream & | input_stream | ) | [static] |
Throws out one histogram's worth of data from the stream.
void WriteSingleHistogramToStream | ( | ostream & | output_stream, | |
const MultiResolutionHistogram * | h | |||
) | [static] |
Write just one histogram to a stream.
Aborts if the stream is bad. See ReadSingleHistogramFromStream for the format.