#ifndef _EBPPS_SKETCH_HPP_
#define _EBPPS_SKETCH_HPP_
#include "common_defs.hpp"
#include "ebpps_sample.hpp"
#include "optional.hpp"
#include "serde.hpp"
#include <random>
#include <string>
#include <vector>
namespace datasketches {
namespace ebpps_constants {
const uint32_t MAX_K = ((uint32_t) 1 << 31) - 2;
}
template<
typename T,
typename A = std::allocator<T>
>
class ebpps_sketch {
public:
static const uint32_t MAX_K = ebpps_constants::MAX_K;
explicit ebpps_sketch(uint32_t k, const A& allocator = A());
void update(const T& item, double weight = 1.0);
void update(T&& item, double weight = 1.0);
void merge(const ebpps_sketch<T, A>& sketch);
void merge(ebpps_sketch<T, A>&& sketch);
using result_type = typename ebpps_sample<T,A>::result_type;
result_type get_result() const;
inline uint32_t get_k() const;
inline uint64_t get_n() const;
inline double get_cumulative_weight() const;
inline double get_c() const;
inline bool is_empty() const;
A get_allocator() const;
void reset();
template<typename SerDe = serde<T>>
inline size_t get_serialized_size_bytes(const SerDe& sd = SerDe()) const;
using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
template<typename SerDe = serde<T>>
vector_bytes serialize(unsigned header_size_bytes = 0, const SerDe& sd = SerDe()) const;
template<typename SerDe = serde<T>>
void serialize(std::ostream& os, const SerDe& sd = SerDe()) const;
template<typename SerDe = serde<T>>
static ebpps_sketch deserialize(const void* bytes, size_t size, const SerDe& sd = SerDe(), const A& allocator = A());
template<typename SerDe = serde<T>>
static ebpps_sketch deserialize(std::istream& is, const SerDe& sd = SerDe(), const A& allocator = A());
string<A> to_string() const;
string<A> items_to_string() const;
typename ebpps_sample<T,A>::const_iterator begin() const;
typename ebpps_sample<T,A>::const_iterator end() const;
private:
static const uint8_t PREAMBLE_LONGS_EMPTY = 1;
static const uint8_t PREAMBLE_LONGS_FULL = 5; static const uint8_t SER_VER = 1;
static const uint8_t FAMILY_ID = 19;
static const uint8_t EMPTY_FLAG_MASK = 4;
static const uint8_t HAS_PARTIAL_ITEM_MASK = 8;
A allocator_;
uint32_t k_; uint64_t n_;
double cumulative_wt_; double wt_max_; double rho_;
ebpps_sample<T,A> sample_;
ebpps_sample<T,A> tmp_;
template<typename O>
void internal_merge(O&& other);
ebpps_sketch(uint32_t k, uint64_t n, double cumulative_wt, double wt_max, double rho,
ebpps_sample<T,A>&& sample, const A& allocator = A());
template<typename FwdItem>
inline void internal_update(FwdItem&& item, double weight);
static uint32_t check_k(uint32_t k);
static void check_preamble_longs(uint8_t preamble_longs, uint8_t flags);
static void check_family_and_serialization_version(uint8_t family_id, uint8_t ser_ver);
static uint32_t validate_and_get_target_size(uint32_t preamble_longs, uint32_t k, uint64_t n);
};
}
#include "ebpps_sketch_impl.hpp"
#endif