/*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#ifndef FOLLY_HISTOGRAM_DEFS_H_
-#define FOLLY_HISTOGRAM_DEFS_H_
+#pragma once
-#include "folly/Conv.h"
+#include <folly/Conv.h>
#include <glog/logging.h>
CHECK_GT(bucketSize_, ValueType(0));
CHECK_LT(min_, max_);
- unsigned int numBuckets = (max - min) / bucketSize;
+ // Deliberately make this a signed type, because we're about
+ // to compare it against max-min, which is nominally signed, too.
+ int numBuckets = (max - min) / bucketSize;
// Round up if the bucket size does not fit evenly
if (numBuckets * bucketSize < max - min) {
++numBuckets;
}
}
+template <typename T, typename BucketType>
+template <typename CountFn>
+uint64_t HistogramBuckets<T, BucketType>::computeTotalCount(
+ CountFn countFromBucket) const {
+ uint64_t count = 0;
+ for (unsigned int n = 0; n < buckets_.size(); ++n) {
+ count += countFromBucket(const_cast<const BucketType&>(buckets_[n]));
+ }
+ return count;
+}
+
template <typename T, typename BucketType>
template <typename CountFn>
unsigned int HistogramBuckets<T, BucketType>::getPercentileBucketIdx(
}
} // folly
-
-#endif // FOLLY_HISTOGRAM_DEFS_H_