Commit 6cb3ae2a authored by Barys Skarabahaty's avatar Barys Skarabahaty Committed by Facebook Github Bot

Improve `rangeAdjust` to accept and return a template type instead of ValueType

Summary: Right now we invoke ValueType ctor (e.g. `ValueType(bucket.count)`) to calculate range adjust for long values, but ValueType can be any type and it should not have a ctro which accepts long

Reviewed By: yfeldblum

Differential Revision: D13986728

fbshipit-source-id: e5b8d826d14fb4c889047b97d88df35654119849
parent df5a0575
......@@ -305,7 +305,7 @@ uint64_t BucketedTimeSeries<VT, CT>::count(TimePoint start, TimePoint end)
TimePoint bucketStart,
TimePoint nextBucketStart) -> bool {
sample_count += this->rangeAdjust(
bucketStart, nextBucketStart, start, end, ValueType(bucket.count));
bucketStart, nextBucketStart, start, end, bucket.count);
return true;
});
......@@ -327,7 +327,7 @@ ReturnType BucketedTimeSeries<VT, CT>::avg(TimePoint start, TimePoint end)
total += this->rangeAdjust(
bucketStart, nextBucketStart, start, end, bucket.sum);
sample_count += this->rangeAdjust(
bucketStart, nextBucketStart, start, end, ValueType(bucket.count));
bucketStart, nextBucketStart, start, end, bucket.count);
return true;
});
......@@ -476,12 +476,13 @@ void BucketedTimeSeries<VT, CT>::forEachBucket(Function fn) const {
* range [10, 16), this will return 60% of the input value.
*/
template <typename VT, typename CT>
VT BucketedTimeSeries<VT, CT>::rangeAdjust(
template <typename ReturnType>
ReturnType BucketedTimeSeries<VT, CT>::rangeAdjust(
TimePoint bucketStart,
TimePoint nextBucketStart,
TimePoint start,
TimePoint end,
ValueType input) const {
ReturnType input) const {
// If nextBucketStart is greater than latestTime_, treat nextBucketStart as
// if it were latestTime_. This makes us more accurate when someone is
// querying for all of the data up to latestTime_. Even though latestTime_
......@@ -499,8 +500,9 @@ VT BucketedTimeSeries<VT, CT>::rangeAdjust(
TimePoint intervalStart = std::max(start, bucketStart);
TimePoint intervalEnd = std::min(end, nextBucketStart);
return input * (intervalEnd - intervalStart) /
(nextBucketStart - bucketStart);
float scale =
(intervalEnd - intervalStart) * 1.f / (nextBucketStart - bucketStart);
return input * scale;
}
template <typename VT, typename CT>
......
......@@ -469,12 +469,13 @@ class BucketedTimeSeries {
TimePoint getEarliestTimeNonEmpty() const;
size_t updateBuckets(TimePoint now);
ValueType rangeAdjust(
template <typename ReturnType>
ReturnType rangeAdjust(
TimePoint bucketStart,
TimePoint nextBucketStart,
TimePoint start,
TimePoint end,
ValueType input) const;
ReturnType input) const;
template <typename Function>
void forEachBucket(TimePoint start, TimePoint end, Function fn) const;
......
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