Skip to content

Commit f1784a0

Browse files
authored
Merge pull request #40 from gjasny/fix-distance-calculation
Fix distance calculation
2 parents cb5d500 + 3726130 commit f1784a0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/histogram.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <algorithm>
2+
#include <iterator>
23
#include <numeric>
34

45
#include "prometheus/histogram.h"
@@ -10,10 +11,10 @@ Histogram::Histogram(const BucketBoundaries& buckets)
1011

1112
void Histogram::Observe(double value) {
1213
// TODO: determine bucket list size at which binary search would be faster
13-
auto bucket_index = std::max(
14-
0L, std::find_if(bucket_boundaries_.begin(), bucket_boundaries_.end(),
15-
[value](double boundary) { return boundary > value; }) -
16-
bucket_boundaries_.begin());
14+
auto bucket_index = static_cast<std::size_t>(std::distance(
15+
bucket_boundaries_.begin(),
16+
std::find_if(bucket_boundaries_.begin(), bucket_boundaries_.end(),
17+
[value](double boundary) { return boundary > value; })));
1718
sum_.Increment(value);
1819
bucket_counts_[bucket_index].Increment();
1920
}

0 commit comments

Comments
 (0)