in quantiles/include/quantiles_sketch_impl.hpp [235:273]
void quantiles_sketch<T, C, A>::merge(FwdSk&& other) {
if (other.is_empty()) {
return; // nothing to do
} else if (!other.is_estimation_mode()) {
// other is exact, stream in regardless of k
for (auto item : other.base_buffer_) {
update(conditional_forward<FwdSk>(item));
}
reset_sorted_view();
return;
}
// other has data and is in estimation mode
if (is_estimation_mode()) {
if (k_ == other.get_k()) {
standard_merge(*this, std::forward<FwdSk>(other));
} else if (k_ > other.get_k()) {
quantiles_sketch sk_copy(std::forward<FwdSk>(other));
downsampling_merge(sk_copy, std::move(*this));
*this = std::move(sk_copy);
} else { // k_ < other.get_k()
downsampling_merge(*this, std::forward<FwdSk>(other));
}
} else {
// exact or empty
quantiles_sketch sk_copy(std::forward<FwdSk>(other));
if (k_ <= other.get_k()) {
if (!is_empty()) {
for (uint16_t i = 0; i < base_buffer_.size(); ++i) {
sk_copy.update(std::move(base_buffer_[i]));
}
}
} else { // k_ > other.get_k()
downsampling_merge(sk_copy, std::move(*this));
}
*this = std::move(sk_copy);
}
reset_sorted_view();
}