Make some types and constexprs public
[folly.git] / folly / stats / Histogram.h
index 86bf997454d705281d88e39b9243620f41534a01..7b7ee1ed3afcc662e7f1dcb53c97f2759d7722e0 100644 (file)
@@ -142,6 +142,18 @@ class HistogramBuckets {
     return min_ + (idx * bucketSize_);
   }
 
+  /**
+   * Computes the total number of values stored across all buckets.
+   *
+   * Runs in O(numBuckets)
+   *
+   * @param countFn A function that takes a const BucketType&, and returns the
+   *                number of values in that bucket
+   * @return Returns the total number of values stored across all buckets
+   */
+  template <typename CountFn>
+  const uint64_t computeTotalCount(CountFn countFromBucket) const;
+
   /**
    * Determine which bucket the specified percentile falls into.
    *
@@ -376,6 +388,16 @@ class Histogram {
     return buckets_.getBucketMax(idx);
   }
 
+  /**
+   * Computes the total number of values stored across all buckets.
+   *
+   * Runs in O(numBuckets)
+   */
+  const uint64_t computeTotalCount() const {
+    CountFromBucket countFn;
+    return buckets_.computeTotalCount(countFn);
+  }
+
   /*
    * Get the bucket that the specified percentile falls into
    *
@@ -416,7 +438,6 @@ class Histogram {
    */
   void toTSV(std::ostream& out, bool skipEmptyBuckets = true) const;
 
- private:
   struct CountFromBucket {
     uint64_t operator()(const Bucket& bucket) const {
       return bucket.count;
@@ -440,6 +461,7 @@ class Histogram {
     }
   };
 
+ private:
   detail::HistogramBuckets<ValueType, Bucket> buckets_;
 };