MCPcopy Create free account
hub / github.com/apache/kvrocks / Add

Method Add

src/types/tdigest.cc:66–83  ·  view source on GitHub ↗

merge one centroid from a sorted centroid stream

Source from the content-addressed store, hash-verified

64
65 // merge one centroid from a sorted centroid stream
66 void Add(const Centroid& centroid) {
67 auto& td = *tdigest_;
68 const double weight = weight_so_far_ + centroid.weight;
69 if (weight <= weight_limit_) {
70 td.back().Merge(centroid);
71 } else {
72 const double quantile = weight_so_far_ / total_weight_;
73 // weight limit should be strictly increasing, until the last centroid
74 if (const double next_weight_limit = total_weight_ * this->Q(this->K(quantile) + 1);
75 next_weight_limit <= weight_limit_) {
76 weight_limit_ = total_weight_;
77 } else {
78 weight_limit_ = next_weight_limit;
79 }
80 td.push_back(centroid); // should never exceed capacity and trigger reallocation
81 }
82 weight_so_far_ = weight;
83 }
84
85 // validate k-size of a tdigest
86 Status Validate(const std::vector<Centroid>& tdigest, double total_weight) const {

Callers

nothing calls this directly

Calls 3

QMethod · 0.80
KMethod · 0.80
MergeMethod · 0.45

Tested by

no test coverage detected