MongoDB  2.7.0
histogram.h
1 
29 #ifndef UTIL_HISTOGRAM_HEADER
30 #define UTIL_HISTOGRAM_HEADER
31 
32 #include <string>
33 #include <stdint.h>
34 
35 namespace mongo {
36 
40  class Histogram {
41  public:
68  struct Options {
69  uint32_t numBuckets;
70  uint32_t bucketSize;
71  uint32_t initialValue;
72 
73  // use exponential buckets?
74  bool exponential;
75 
76  Options()
77  : numBuckets(0)
78  , bucketSize(0)
79  , initialValue(0)
80  , exponential(false) {}
81  };
82  explicit Histogram( const Options& opts );
83  ~Histogram();
84 
88  void insert( uint32_t element );
89 
94  std::string toHTML() const;
95 
96  // testing interface below -- consider it private
97 
101  uint64_t getCount( uint32_t bucket ) const;
102 
107  uint32_t getBoundary( uint32_t bucket ) const;
108 
112  uint32_t getBucketsNum() const;
113 
114  private:
120  uint32_t _findBucket( uint32_t element ) const;
121 
122  uint32_t _initialValue; // no value lower than it is recorded
123  uint32_t _numBuckets; // total buckets in the histogram
124 
125  // all below owned here
126  uint32_t* _boundaries; // maximum element of each bucket
127  uint64_t* _buckets; // current count of each bucket
128 
129  Histogram( const Histogram& );
130  Histogram& operator=( const Histogram& );
131  };
132 
133 } // namespace mongo
134 
135 #endif // UTIL_HISTOGRAM_HEADER
uint64_t getCount(uint32_t bucket) const
Return the count for the 'bucket'-th bucket.
Definition: histogram.cpp:107
void insert(uint32_t element)
Find the bucket that 'element' falls into and increment its count.
Definition: histogram.cpp:77
std::string toHTML() const
Render the histogram as string that can be used inside an HTML doc.
Definition: histogram.cpp:83
Construct a histogram with 'numBuckets' buckets, optionally having the first bucket start at 'initial...
Definition: histogram.h:68
uint32_t getBoundary(uint32_t bucket) const
Return the maximum element that would fall in the 'bucket'-th bucket.
Definition: histogram.cpp:113
uint32_t getBucketsNum() const
Return the number of buckets in this histogram.
Definition: histogram.cpp:119
A histogram for a 32-bit integer range.
Definition: histogram.h:40