in kll/include/kll_sketch_impl.hpp [208:230]
void kll_sketch<T, C, A>::merge(FwdSk&& other) {
if (other.is_empty()) return;
if (m_ != other.m_) {
throw std::invalid_argument("incompatible M: " + std::to_string(m_) + " and " + std::to_string(other.m_));
}
if (is_empty()) {
min_item_.emplace(conditional_forward<FwdSk>(*other.min_item_));
max_item_.emplace(conditional_forward<FwdSk>(*other.max_item_));
} else {
if (comparator_(*other.min_item_, *min_item_)) *min_item_ = conditional_forward<FwdSk>(*other.min_item_);
if (comparator_(*max_item_, *other.max_item_)) *max_item_ = conditional_forward<FwdSk>(*other.max_item_);
}
const uint64_t final_n = n_ + other.n_;
for (uint32_t i = other.levels_[0]; i < other.levels_[1]; i++) {
const uint32_t index = internal_update();
new (&items_[index]) T(conditional_forward<FwdSk>(other.items_[i]));
}
if (other.num_levels_ >= 2) merge_higher_levels(other, final_n);
n_ = final_n;
if (other.is_estimation_mode()) min_k_ = std::min(min_k_, other.min_k_);
assert_correct_total_weight();
reset_sorted_view();
}