#ifndef CPC_UNION_HPP_
#define CPC_UNION_HPP_
#include <string>
#include "cpc_sketch.hpp"
#include "common_defs.hpp"
namespace datasketches {
using cpc_union = cpc_union_alloc<std::allocator<uint8_t>>;
template<typename A>
class cpc_union_alloc {
public:
using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
using vector_u64 = std::vector<uint64_t, typename std::allocator_traits<A>::template rebind_alloc<uint64_t>>;
explicit cpc_union_alloc(uint8_t lg_k = cpc_constants::DEFAULT_LG_K, uint64_t seed = DEFAULT_SEED, const A& allocator = A());
cpc_union_alloc(const cpc_union_alloc<A>& other);
cpc_union_alloc(cpc_union_alloc<A>&& other) noexcept;
~cpc_union_alloc();
cpc_union_alloc<A>& operator=(const cpc_union_alloc<A>& other);
cpc_union_alloc<A>& operator=(cpc_union_alloc<A>&& other) noexcept;
void update(const cpc_sketch_alloc<A>& sketch);
void update(cpc_sketch_alloc<A>&& sketch);
cpc_sketch_alloc<A> get_result() const;
private:
using AllocU8 = typename std::allocator_traits<A>::template rebind_alloc<uint8_t>;
using AllocU64 = typename std::allocator_traits<A>::template rebind_alloc<uint64_t>;
using AllocCpc = typename std::allocator_traits<A>::template rebind_alloc<cpc_sketch_alloc<A>>;
uint8_t lg_k;
uint64_t seed;
cpc_sketch_alloc<A>* accumulator;
vector_u64 bit_matrix;
template<typename S> void internal_update(S&& sketch);
cpc_sketch_alloc<A> get_result_from_accumulator() const;
cpc_sketch_alloc<A> get_result_from_bit_matrix() const;
void switch_to_bit_matrix();
void walk_table_updating_sketch(const u32_table<A>& table);
void or_table_into_matrix(const u32_table<A>& table);
void or_window_into_matrix(const vector_bytes& sliding_window, uint8_t offset, uint8_t src_lg_k);
void or_matrix_into_matrix(const vector_u64& src_matrix, uint8_t src_lg_k);
void reduce_k(uint8_t new_lg_k);
};
}
#include "cpc_union_impl.hpp"
#endif