00001 // histogram.h 00002 00019 #ifndef UTIL_HISTOGRAM_HEADER 00020 #define UTIL_HISTOGRAM_HEADER 00021 00022 #include "../pch.h" 00023 00024 #include <string> 00025 00026 namespace mongo { 00027 00028 using std::string; 00029 00033 class Histogram { 00034 public: 00061 struct Options { 00062 boost::uint32_t numBuckets; 00063 boost::uint32_t bucketSize; 00064 boost::uint32_t initialValue; 00065 00066 // use exponential buckets? 00067 bool exponential; 00068 00069 Options() 00070 : numBuckets(0) 00071 , bucketSize(0) 00072 , initialValue(0) 00073 , exponential(false) {} 00074 }; 00075 explicit Histogram( const Options& opts ); 00076 ~Histogram(); 00077 00081 void insert( boost::uint32_t element ); 00082 00087 string toHTML() const; 00088 00089 // testing interface below -- consider it private 00090 00094 boost::uint64_t getCount( boost::uint32_t bucket ) const; 00095 00100 boost::uint32_t getBoundary( boost::uint32_t bucket ) const; 00101 00105 boost::uint32_t getBucketsNum() const; 00106 00107 private: 00113 boost::uint32_t _findBucket( boost::uint32_t element ) const; 00114 00115 boost::uint32_t _initialValue; // no value lower than it is recorded 00116 boost::uint32_t _numBuckets; // total buckets in the histogram 00117 00118 // all below owned here 00119 boost::uint32_t* _boundaries; // maximum element of each bucket 00120 boost::uint64_t* _buckets; // current count of each bucket 00121 00122 Histogram( const Histogram& ); 00123 Histogram& operator=( const Histogram& ); 00124 }; 00125 00126 } // namespace mongo 00127 00128 #endif // UTIL_HISTOGRAM_HEADER