20#ifndef _EBPPS_SKETCH_HPP_
21#define _EBPPS_SKETCH_HPP_
23#include "common_defs.hpp"
24#include "ebpps_sample.hpp"
25#include "optional.hpp"
35namespace ebpps_constants {
37 const uint32_t
MAX_K = ((uint32_t) 1 << 31) - 2;
62 typename A = std::allocator<T>
74 explicit ebpps_sketch(uint32_t k,
const A& allocator = A());
84 void update(
const T& item,
double weight = 1.0);
94 void update(T&& item,
double weight = 1.0);
114 using result_type =
typename ebpps_sample<T,A>::result_type;
125 inline uint32_t
get_k()
const;
132 inline uint64_t
get_n()
const;
152 inline double get_c()
const;
176 template<
typename SerDe = serde<T>>
181 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
191 template<
typename SerDe = serde<T>>
192 vector_bytes
serialize(
unsigned header_size_bytes = 0,
const SerDe& sd = SerDe())
const;
199 template<
typename SerDe = serde<T>>
200 void serialize(std::ostream& os,
const SerDe& sd = SerDe())
const;
210 template<
typename SerDe = serde<T>>
220 template<
typename SerDe = serde<T>>
244 typename ebpps_sample<T,A>::const_iterator
begin()
const;
252 typename ebpps_sample<T,A>::const_iterator
end()
const;
255 static const uint8_t PREAMBLE_LONGS_EMPTY = 1;
256 static const uint8_t PREAMBLE_LONGS_FULL = 5;
257 static const uint8_t SER_VER = 1;
258 static const uint8_t FAMILY_ID = 19;
259 static const uint8_t EMPTY_FLAG_MASK = 4;
260 static const uint8_t HAS_PARTIAL_ITEM_MASK = 8;
266 double cumulative_wt_;
270 ebpps_sample<T,A> sample_;
272 ebpps_sample<T,A> tmp_;
277 void internal_merge(O&& other);
279 ebpps_sketch(uint32_t k, uint64_t n,
double cumulative_wt,
double wt_max,
double rho,
280 ebpps_sample<T,A>&& sample,
const A& allocator = A());
282 template<
typename FwdItem>
283 inline void internal_update(FwdItem&& item,
double weight);
286 static uint32_t check_k(uint32_t k);
287 static void check_preamble_longs(uint8_t preamble_longs, uint8_t flags);
288 static void check_family_and_serialization_version(uint8_t family_id, uint8_t ser_ver);
289 static uint32_t validate_and_get_target_size(uint32_t preamble_longs, uint32_t k, uint64_t n);
294#include "ebpps_sketch_impl.hpp"
An implementation of an Exact and Bounded Sampling Proportional to Size sketch.
Definition ebpps_sketch.hpp:64
string< A > items_to_string() const
Prints the raw sketch items to a string.
Definition ebpps_sketch_impl.hpp:112
void update(const T &item, double weight=1.0)
Updates this sketch with the given data item with the given weight.
Definition ebpps_sketch_impl.hpp:127
vector_bytes serialize(unsigned header_size_bytes=0, const SerDe &sd=SerDe()) const
This method serializes the sketch as a vector of bytes.
ebpps_sample< T, A >::const_iterator end() const
Iterator pointing to the past-the-end item in the sketch.
Definition ebpps_sketch_impl.hpp:524
bool is_empty() const
Returns true if the sketch is empty.
Definition ebpps_sketch_impl.hpp:82
ebpps_sample< T, A >::const_iterator begin() const
Iterator pointing to the first item in the sketch.
Definition ebpps_sketch_impl.hpp:519
size_t get_serialized_size_bytes(const SerDe &sd=SerDe()) const
Computes size needed to serialize the current state of the sketch.
Definition ebpps_sketch_impl.hpp:320
double get_cumulative_weight() const
Returns the cumulative weight of items processed by the sketch.
Definition ebpps_sketch_impl.hpp:77
A get_allocator() const
Returns an instance of the allocator for this sketch.
Definition ebpps_sketch_impl.hpp:122
void merge(const ebpps_sketch< T, A > &sketch)
Merges the provided sketch into the current one.
Definition ebpps_sketch_impl.hpp:199
static ebpps_sketch deserialize(const void *bytes, size_t size, const SerDe &sd=SerDe(), const A &allocator=A())
This method deserializes a sketch from a given array of bytes.
void reset()
Resets the sketch to its default, empty state.
Definition ebpps_sketch_impl.hpp:87
double get_c() const
Returns the expected number of samples returned upon a call to get_result() or the creation of an ite...
Definition ebpps_sketch_impl.hpp:72
static ebpps_sketch deserialize(std::istream &is, const SerDe &sd=SerDe(), const A &allocator=A())
This method deserializes a sketch from a given stream.
string< A > to_string() const
Prints a summary of the sketch.
Definition ebpps_sketch_impl.hpp:96
result_type get_result() const
Returns a copy of the current sample, as a std::vector.
Definition ebpps_sketch_impl.hpp:163
uint32_t get_k() const
Returns the configured maximum sample size.
Definition ebpps_sketch_impl.hpp:62
uint64_t get_n() const
Returns the number of items processed by the sketch, regardless of item weight.
Definition ebpps_sketch_impl.hpp:67
const uint32_t MAX_K
maximum value of parameter K
Definition ebpps_sketch.hpp:37
DataSketches namespace.
Definition binomial_bounds.hpp:38