Skip to content

Commit 8fd753c

Browse files
committed
fix(tdigest): fix incorrect min/max default initialization
CentroidsWithDelta struct was default-initializing min and max to 0, which caused incorrect behavior when merging empty tdigests. Also delete Reset({}) overload to prevent accidental misuse. Assisted-by: Claude Code:glm-5
1 parent 8d02125 commit 8fd753c

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/types/tdigest.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ class TDigest {
355355
void Merge(const std::vector<TDigest>& others);
356356
void Add(const std::vector<double>& items);
357357
void Reset(const CentroidsWithDelta& centroid_list);
358+
void Reset(std::initializer_list<CentroidsWithDelta>) = delete;
358359
void Reset();
359360
CentroidsWithDelta DumpCentroids() const;
360361

src/types/tdigest.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <fmt/format.h>
2424

25+
#include <limits>
2526
#include <map>
2627
#include <numeric>
2728
#include <variant>
@@ -47,10 +48,10 @@ struct Centroid {
4748

4849
struct CentroidsWithDelta {
4950
std::vector<Centroid> centroids;
50-
uint64_t delta;
51-
double min;
52-
double max;
53-
double total_weight;
51+
uint64_t delta = 0;
52+
double min = std::numeric_limits<double>::max();
53+
double max = std::numeric_limits<double>::lowest();
54+
double total_weight = 0;
5455
};
5556

5657
StatusOr<CentroidsWithDelta> TDigestMerge(const std::vector<CentroidsWithDelta>& centroids_list, uint64_t delta);

0 commit comments

Comments
 (0)