20#ifndef THETA_UNION_BASE_IMPL_HPP_
21#define THETA_UNION_BASE_IMPL_HPP_
26#include "conditional_forward.hpp"
27#include "theta_helpers.hpp"
31template<
typename EN,
typename EK,
typename P,
typename S,
typename CS,
typename A>
32theta_union_base<EN, EK, P, S, CS, A>::theta_union_base(uint8_t lg_cur_size, uint8_t lg_nom_size, resize_factor rf,
33 float p, uint64_t theta, uint64_t seed,
const P& policy,
const A& allocator):
35table_(lg_cur_size, lg_nom_size, rf, p, theta, seed, allocator),
36union_theta_(table_.theta_)
39template<
typename EN,
typename EK,
typename P,
typename S,
typename CS,
typename A>
41void theta_union_base<EN, EK, P, S, CS, A>::update(SS&& sketch) {
42 if (sketch.is_empty())
return;
43 if (sketch.get_seed_hash() != compute_seed_hash(table_.seed_))
throw std::invalid_argument(
"seed hash mismatch");
44 table_.is_empty_ =
false;
45 union_theta_ = std::min(union_theta_, sketch.get_theta64());
46 for (
auto&& entry: sketch) {
47 const uint64_t hash = EK()(entry);
48 if (hash < union_theta_ && hash < table_.theta_) {
49 auto result = table_.find(hash);
51 table_.insert(result.first, conditional_forward<SS>(entry));
53 policy_(*result.first, conditional_forward<SS>(entry));
56 if (sketch.is_ordered())
break;
59 union_theta_ = std::min(union_theta_, table_.theta_);
62template<
typename EN,
typename EK,
typename P,
typename S,
typename CS,
typename A>
63CS theta_union_base<EN, EK, P, S, CS, A>::get_result(
bool ordered)
const {
64 std::vector<EN, A> entries(table_.allocator_);
65 if (table_.is_empty_)
return CS(
true,
true, compute_seed_hash(table_.seed_), union_theta_, std::move(entries));
66 entries.reserve(table_.num_entries_);
67 uint64_t theta = std::min(union_theta_, table_.theta_);
68 const uint32_t nominal_num = 1 << table_.lg_nom_size_;
69 if (union_theta_ >= table_.theta_) {
70 std::copy_if(table_.begin(), table_.end(), std::back_inserter(entries), key_not_zero<EN, EK>());
72 std::copy_if(table_.begin(), table_.end(), std::back_inserter(entries), key_not_zero_less_than<uint64_t, EN, EK>(theta));
74 theta = trim_to_nominal<EK>(entries, nominal_num, theta);
75 if (ordered) std::sort(entries.begin(), entries.end(), comparator());
76 return CS(table_.is_empty_, ordered, compute_seed_hash(table_.seed_), theta, std::move(entries));
79template<
typename EN,
typename EK,
typename P,
typename S,
typename CS,
typename A>
80const P& theta_union_base<EN, EK, P, S, CS, A>::get_policy()
const {
84template<
typename EN,
typename EK,
typename P,
typename S,
typename CS,
typename A>
85void theta_union_base<EN, EK, P, S, CS, A>::reset() {
87 union_theta_ = table_.theta_;
DataSketches namespace.
Definition binomial_bounds.hpp:38