20 #ifndef _EBPPS_SAMPLE_HPP_
21 #define _EBPPS_SAMPLE_HPP_
23 #include "common_defs.hpp"
24 #include "optional.hpp"
34 typename A = std::allocator<T>
38 explicit ebpps_sample(uint32_t k,
const A& allocator = A());
42 ebpps_sample(std::vector<T, A>&& data, optional<T>&& partial_item,
double c,
const A& allocator = A());
46 void replace_content(TT&& item,
double theta);
49 void downsample(
double theta);
51 template<
typename FwdSample>
52 void merge(FwdSample&& other);
55 using result_type = std::vector<T, A>;
56 result_type get_sample()
const;
62 result_type get_full_items()
const;
66 bool has_partial_item()
const;
67 T get_partial_item()
const;
69 string<A> to_string()
const;
77 inline uint32_t get_num_retained_items()
const;
85 template<
typename TT = T,
typename SerDe = serde<T>,
typename std::enable_if<std::is_arithmetic<TT>::value,
int>::type = 0>
86 inline size_t get_serialized_size_bytes(
const SerDe& sd = SerDe())
const;
94 template<
typename TT = T,
typename SerDe = serde<T>,
typename std::enable_if<!std::is_arithmetic<TT>::value,
int>::type = 0>
95 inline size_t get_serialized_size_bytes(
const SerDe& sd = SerDe())
const;
99 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
108 template<
typename SerDe = serde<T>>
109 size_t serialize(uint8_t* ptr,
const uint8_t* end_ptr,
const SerDe& sd = SerDe())
const;
116 template<
typename SerDe = serde<T>>
117 void serialize(std::ostream& os,
const SerDe& sd = SerDe())
const;
127 template<
typename SerDe = serde<T>>
128 static std::pair<ebpps_sample, size_t> deserialize(
const uint8_t* ptr,
size_t size,
const SerDe& sd = SerDe(),
const A& allocator = A());
137 template<
typename SerDe = serde<T>>
138 static ebpps_sample deserialize(std::istream& is,
const SerDe& sd = SerDe(),
const A& allocator = A());
140 class const_iterator;
148 const_iterator begin()
const;
156 const_iterator end()
const;
161 optional<T> partial_item_;
162 std::vector<T, A> data_;
164 template<
typename FwdItem>
165 inline void set_partial(FwdItem&& item);
166 void swap_with_partial();
167 void move_one_to_partial();
168 void subsample(uint32_t num_samples);
170 static inline uint32_t random_idx(uint32_t max);
171 static inline double next_double();
173 friend class const_iterator;
176 template<
typename T,
typename A>
177 class ebpps_sample<T, A>::const_iterator {
179 using iterator_category = std::input_iterator_tag;
180 using value_type =
const T&;
181 using difference_type = void;
182 using pointer =
const return_value_holder<value_type>;
183 using reference = value_type;
185 const_iterator(
const const_iterator& other);
186 const_iterator& operator++();
187 const_iterator& operator++(
int);
188 bool operator==(
const const_iterator& other)
const;
189 bool operator!=(
const const_iterator& other)
const;
190 reference operator*()
const;
191 pointer operator->()
const;
194 static const size_t PARTIAL_IDX =
static_cast<size_t>(-1);
197 const_iterator(
const ebpps_sample<T, A>* sample);
199 const ebpps_sample<T, A>* sample_;
203 friend class ebpps_sample;
208 #include "ebpps_sample_impl.hpp"
DataSketches namespace.
Definition: binomial_bounds.hpp:38