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

Method MergeInput

src/types/tdigest.cc:227–259  ·  view source on GitHub ↗

merge input data with current tdigest

Source from the content-addressed store, hash-verified

225
226 // merge input data with current tdigest
227 void MergeInput(std::vector<double> input) {
228 total_weight_ += static_cast<double>(input.size());
229
230 std::sort(input.begin(), input.end());
231 if (input.empty()) {
232 return;
233 }
234
235 // pick next minimal centroid from input and tdigest, feed to merger
236 merger_.Reset(total_weight_, &tdigests_[1 - current_]);
237 const auto& td = tdigests_[current_];
238 uint32_t tdigest_index = 0;
239 uint32_t input_index = 0;
240 while (tdigest_index < td.size() && input_index < input.size()) {
241 if (td[tdigest_index].mean < input[input_index]) {
242 merger_.Add(td[tdigest_index]);
243 ++tdigest_index;
244 } else {
245 merger_.Add(Centroid{input[input_index], 1});
246 ++input_index;
247 }
248 }
249 while (tdigest_index < td.size()) {
250 merger_.Add(td[tdigest_index]);
251 ++tdigest_index;
252 }
253 while (input_index < input.size()) {
254 merger_.Add(Centroid{input[input_index], 1});
255 ++input_index;
256 }
257 merger_.Reset(0, nullptr);
258 current_ = 1 - current_;
259 }
260
261 double Quantile(double q) const {
262 const auto& td = tdigests_[current_];

Callers 1

AddMethod · 0.80

Calls 4

beginMethod · 0.80
endMethod · 0.80
ResetMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected