multi-resolution-histogram.h

Go to the documentation of this file.
00001 // Copyright 2007, Massachusetts Institute of Technology.
00002 // The use of this code is permitted for research only. There is
00003 // absolutely no warranty for this software.
00004 //
00005 // Author: John Lee (jjl@mit.edu)
00006 //
00007 
00008 #ifndef HISTOGRAMS_MULTI_RESOLUTION_HISTOGRAM_H
00009 #define HISTOGRAMS_MULTI_RESOLUTION_HISTOGRAM_H
00010 
00011 #include <iostream>
00012 #include "histograms/bin.h"
00013 #include "tree/sparse-tree.cc"
00014 
00015 using namespace std;
00016 
00017 namespace libpmk {
00018 template class SparseTree<Bin>;
00019 
00022 
00028 class MultiResolutionHistogram {
00029 public:
00030   MultiResolutionHistogram() { }
00031 
00032   int size() const { return tree_.size(); }
00033 
00035 
00038   Bin* bin(LargeIndex index);
00039 
00041 
00046   Bin* bin(LargeIndex index, Bin* finger);
00047 
00049   Bin* root() { return tree_.root(); }
00050   Bin* const root() const { return tree_.root(); }
00051 
00053 
00070   Bin* add_bin(const Bin& new_bin);
00071 
00072   // Same as add_bin(), except if the user already has a pointer to the
00073   // parent, use that. If the parent is invalid, NULL is returned and
00074   // no bin is added. In order for this to work properly, the parent pointer
00075   // MUST be a bin which can be accessed through child pointers of
00076   // root_bin_. In other words, this MultiResolutionHistogram must be the
00077   // owner of the parent that you pass into it. We do NOT check for this;
00078   // it is up to the client to make sure of it.
00080 
00086   Bin* add_bin(const Bin& new_bin, Bin* finger);
00087 
00089   void remove_bin(Bin* finger);
00090 
00092 
00099   static vector<MultiResolutionHistogram*>
00100   ReadFromStream(istream& input_stream);
00101 
00103 
00106   static vector<MultiResolutionHistogram*>
00107   ReadFromFile(const char* filename);
00108 
00110 
00121   static vector<MultiResolutionHistogram*>
00122   ReadSelectionFromStream(istream& input_stream,
00123                           int start, int selection_size);
00124 
00126 
00129   static vector<MultiResolutionHistogram*>
00130   ReadSelectionFromFile(const char* filename, int start,
00131                         int selection_size);
00133 
00137   static void WriteToStream(ostream& output_stream,
00138                             const vector<MultiResolutionHistogram*>& hists);
00139 
00141 
00144   static void WriteToFile(const char* filename,
00145                           const vector<MultiResolutionHistogram*>& hists);
00146 
00148 
00161   static MultiResolutionHistogram*
00162   ReadSingleHistogramFromStream(istream& input_stream);
00163 
00165   static void IgnoreSingleHistogramFromStream(istream& input_stream);
00166 
00168 
00172   static void WriteSingleHistogramToStream(ostream& output_stream,
00173                                            const MultiResolutionHistogram* h);
00174 
00175 private:
00176   SparseTree<Bin> tree_;
00177 };
00178 }  // namespace libpmk
00179 #endif  // HISTOGRAMS_MULTI_RESOLUTION_HISTOGRAM_H

Generated on Fri Sep 21 11:39:04 2007 for libpmk2 by  doxygen 1.5.1