void HllVal::agg_parse_and_cal(FunctionContext* ctx, const HllVal& other) {
    doris::HllSetResolver resolver;

    // zero size means the src input is a HyperLogLog object
    if (other.len == 0) {
        auto* hll = reinterpret_cast<doris::HyperLogLog*>(other.ptr);
        uint8_t* other_ptr = ctx->allocate(doris::HLL_COLUMN_DEFAULT_LEN);
        int other_len = hll->serialize(ptr);
        resolver.init((char*)other_ptr, other_len);
    } else {
        resolver.init((char*)other.ptr, other.len);
    }

    resolver.parse();

    if (resolver.get_hll_data_type() == doris::HLL_DATA_EMPTY) {
        return;
    }

    uint8_t* pdata = ptr + 1;
    int data_len = doris::HLL_REGISTERS_COUNT;

    if (resolver.get_hll_data_type() == doris::HLL_DATA_EXPLICIT) {
        for (int i = 0; i < resolver.get_explicit_count(); i++) {
            uint64_t hash_value = resolver.get_explicit_value(i);
            int idx = hash_value % data_len;
            uint8_t first_one_bit = __builtin_ctzl(hash_value >> doris::HLL_COLUMN_PRECISION) + 1;
            pdata[idx] = std::max(pdata[idx], first_one_bit);
        }
    } else if (resolver.get_hll_data_type() == doris::HLL_DATA_SPARSE) {
        std::map<doris::HllSetResolver::SparseIndexType, doris::HllSetResolver::SparseValueType>&
                sparse_map = resolver.get_sparse_map();
        for (std::map<doris::HllSetResolver::SparseIndexType,
                      doris::HllSetResolver::SparseValueType>::iterator iter = sparse_map.begin();
             iter != sparse_map.end(); ++iter) {
            pdata[iter->first] = std::max(pdata[iter->first], (uint8_t)iter->second);
        }
    } else if (resolver.get_hll_data_type() == doris::HLL_DATA_FULL) {
        char* full_value = resolver.get_full_value();
        for (int i = 0; i < doris::HLL_REGISTERS_COUNT; i++) {
            pdata[i] = std::max(pdata[i], (uint8_t)full_value[i]);
        }
    }
}
void HllVal::agg_parse_and_cal(FunctionContext* ctx, const HllVal& other) {
    doris::HllSetResolver resolver;

     
    if (other.len == 0) {
        auto* hll = reinterpret_cast<doris::HyperLogLog*>(other.ptr);
        uint8_t* other_ptr = ctx->allocate(doris::HLL_COLUMN_DEFAULT_LEN);
        int other_len = hll->serialize(ptr);
        resolver.init((char*)other_ptr, other_len);
    } else {
        resolver.init((char*)other.ptr, other.len);
    }

    resolver.parse();

    if (resolver.get_hll_data_type() == doris::HLL_DATA_EMPTY) {
        return;
    }

    uint8_t* pdata = ptr + 1;
    int data_len = doris::HLL_REGISTERS_COUNT;

    if (resolver.get_hll_data_type() == doris::HLL_DATA_EXPLICIT) {
        for (int i = 0; i < resolver.get_explicit_count(); i++) {
            uint64_t hash_value = resolver.get_explicit_value(i);
            int idx = hash_value % data_len;
            uint8_t first_one_bit = __builtin_ctzl(hash_value >> doris::HLL_COLUMN_PRECISION) + 1;
            pdata[idx] = std::max(pdata[idx], first_one_bit);
        }
    } else if (resolver.get_hll_data_type() == doris::HLL_DATA_SPARSE) {
        std::map<doris::HllSetResolver::SparseIndexType, doris::HllSetResolver::SparseValueType>&
                sparse_map = resolver.get_sparse_map();
        for (std::map<doris::HllSetResolver::SparseIndexType,
                      doris::HllSetResolver::SparseValueType>::iterator iter = sparse_map.begin();
             iter != sparse_map.end(); ++iter) {
            pdata[iter->first] = std::max(pdata[iter->first], (uint8_t)iter->second);
        }
    } else if (resolver.get_hll_data_type() == doris::HLL_DATA_FULL) {
        char* full_value = resolver.get_full_value();
        for (int i = 0; i < doris::HLL_REGISTERS_COUNT; i++) {
            pdata[i] = std::max(pdata[i], (uint8_t)full_value[i]);
        }
    }
}