in hll/include/HllUnion-internal.hpp [230:266]
void hll_union_alloc<A>::union_impl(const hll_sketch_alloc<A>& sketch, uint8_t lg_max_k) {
const HllSketchImpl<A>* src_impl = sketch.sketch_impl; //default
HllSketchImpl<A>* dst_impl = gadget_.sketch_impl; //default
if (src_impl->getCurMode() == LIST || src_impl->getCurMode() == SET) {
if (dst_impl->isEmpty() && src_impl->getLgConfigK() == dst_impl->getLgConfigK()) {
dst_impl = src_impl->copyAs(HLL_8);
gadget_.sketch_impl->get_deleter()(gadget_.sketch_impl); // gadget to be replaced
} else {
const CouponList<A>* src = static_cast<const CouponList<A>*>(src_impl);
for (auto coupon: *src) {
dst_impl = leak_free_coupon_update(dst_impl, coupon); //assignment required
}
}
} else if (!dst_impl->isEmpty()) { // src is HLL
if (dst_impl->getCurMode() == LIST || dst_impl->getCurMode() == SET) {
// swap so that src is LIST or SET, tgt is HLL
// use lg_max_k because LIST has effective K of 2^26
const CouponList<A>* src = static_cast<const CouponList<A>*>(dst_impl);
dst_impl = copy_or_downsample(src_impl, lg_max_k);
static_cast<Hll8Array<A>*>(dst_impl)->mergeList(*src);
gadget_.sketch_impl->get_deleter()(gadget_.sketch_impl); // gadget to be replaced
} else { // gadget is HLL
if (src_impl->getLgConfigK() < dst_impl->getLgConfigK()) {
dst_impl = copy_or_downsample(dst_impl, sketch.get_lg_config_k());
gadget_.sketch_impl->get_deleter()(gadget_.sketch_impl); // gadget to be replaced
}
const HllArray<A>* src = static_cast<const HllArray<A>*>(src_impl);
static_cast<Hll8Array<A>*>(dst_impl)->mergeHll(*src);
dst_impl->putOutOfOrderFlag(true);
static_cast<Hll8Array<A>*>(dst_impl)->putHipAccum(0);
}
} else { // src is HLL, gadget is empty
dst_impl = copy_or_downsample(src_impl, lg_max_k);
gadget_.sketch_impl->get_deleter()(gadget_.sketch_impl); // gadget to be replaced
}
gadget_.sketch_impl = dst_impl; // gadget replaced
}