Commit 58cbf30c authored by Chad Austin's avatar Chad Austin Committed by Facebook Github Bot

minor refactoring in folly/stats

Summary:
While wrapping my head around the TDigest code, I made a few small
drive-by clean-ups.

Reviewed By: yfeldblum

Differential Revision: D16478284

fbshipit-source-id: aaf289a57ef633f0f1527263beffb7c0edf596d1
parent 11855c21
......@@ -26,9 +26,9 @@ QuantileEstimates estimatesFromDigest(
result.quantiles.reserve(quantiles.size());
result.sum = digest.sum();
result.count = digest.count();
for (auto it = quantiles.begin(); it != quantiles.end(); ++it) {
for (auto& quantile : quantiles) {
result.quantiles.push_back(
std::make_pair(*it, digest.estimateQuantile(*it)));
std::make_pair(quantile, digest.estimateQuantile(quantile)));
}
return result;
}
......
......@@ -211,8 +211,8 @@ TDigest TDigest::merge(sorted_equivalent_t, Range<const double*> sortedValues)
TDigest TDigest::merge(Range<const TDigest*> digests) {
size_t nCentroids = 0;
for (auto it = digests.begin(); it != digests.end(); it++) {
nCentroids += it->centroids_.size();
for (const auto& digest : digests) {
nCentroids += digest.centroids_.size();
}
if (nCentroids == 0) {
......@@ -232,16 +232,16 @@ TDigest TDigest::merge(Range<const TDigest*> digests) {
double min = std::numeric_limits<double>::infinity();
double max = -std::numeric_limits<double>::infinity();
for (auto it = digests.begin(); it != digests.end(); it++) {
for (const auto& digest : digests) {
starts.push_back(centroids.end());
double curCount = it->count();
double curCount = digest.count();
if (curCount > 0) {
DCHECK(!std::isnan(it->min_));
DCHECK(!std::isnan(it->max_));
min = std::min(min, it->min_);
max = std::max(max, it->max_);
DCHECK(!std::isnan(digest.min_));
DCHECK(!std::isnan(digest.max_));
min = std::min(min, digest.min_);
max = std::max(max, digest.max_);
count += curCount;
for (const auto& centroid : it->centroids_) {
for (const auto& centroid : digest.centroids_) {
centroids.push_back(centroid);
}
}
......
......@@ -50,6 +50,7 @@ DigestT DigestBuilder<DigestT>::build() {
}
std::vector<DigestT> digests;
digests.reserve(digestPtrs.size());
for (auto& digestPtr : digestPtrs) {
digests.push_back(std::move(*digestPtr));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment