datasketches-cpp
Loading...
Searching...
No Matches
frequent_items_sketch_impl.hpp
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef FREQUENT_ITEMS_SKETCH_IMPL_HPP_
21#define FREQUENT_ITEMS_SKETCH_IMPL_HPP_
22
23#include <cstring>
24#include <limits>
25#include <sstream>
26#include <stdexcept>
27#include <vector>
28
29#include "memory_operations.hpp"
30
31namespace datasketches {
32
33// clang++ seems to require this declaration for CMAKE_BUILD_TYPE='Debug"
34template<typename T, typename W, typename H, typename E, typename A>
35const uint8_t frequent_items_sketch<T, W, H, E, A>::LG_MIN_MAP_SIZE;
36
37template<typename T, typename W, typename H, typename E, typename A>
38frequent_items_sketch<T, W, H, E, A>::frequent_items_sketch(uint8_t lg_max_map_size, uint8_t lg_start_map_size,
39 const E& equal, const A& allocator):
40total_weight(0),
41offset(0),
42map(
43 std::max(lg_start_map_size, frequent_items_sketch::LG_MIN_MAP_SIZE),
44 std::max(lg_max_map_size, frequent_items_sketch::LG_MIN_MAP_SIZE),
45 equal,
46 allocator
47)
48{
49 if (lg_start_map_size > lg_max_map_size) { throw std::invalid_argument("starting size must not be greater than maximum size"); }
50}
51
52template<typename T, typename W, typename H, typename E, typename A>
53void frequent_items_sketch<T, W, H, E, A>::update(const T& item, W weight) {
54 check_weight(weight);
55 if (weight == 0) { return; }
56 total_weight += weight;
57 offset += map.adjust_or_insert(item, weight);
58}
59
60template<typename T, typename W, typename H, typename E, typename A>
62 check_weight(weight);
63 if (weight == 0) { return; }
64 total_weight += weight;
65 offset += map.adjust_or_insert(std::move(item), weight);
66}
67
68template<typename T, typename W, typename H, typename E, typename A>
70 if (other.is_empty()) { return; }
71 const W merged_total_weight = total_weight + other.get_total_weight(); // for correction at the end
72 for (auto it: other.map) {
73 update(it.first, it.second);
74 }
75 offset += other.offset;
76 total_weight = merged_total_weight;
77}
78
79template<typename T, typename W, typename H, typename E, typename A>
81 if (other.is_empty()) { return; }
82 const W merged_total_weight = total_weight + other.get_total_weight(); // for correction at the end
83 for (auto it: other.map) {
84 update(std::move(it.first), it.second);
85 }
86 offset += other.offset;
87 total_weight = merged_total_weight;
88}
89
90template<typename T, typename W, typename H, typename E, typename A>
92 map = reverse_purge_hash_map<T, W, H, E, A>(LG_MIN_MAP_SIZE, map.get_lg_max_size(), map.get_equal(), map.get_allocator());
93 total_weight = 0;
94 offset = 0;
95}
96
97template<typename T, typename W, typename H, typename E, typename A>
99 // a purge may clear all counters while offset and total_weight remain non-zero;
100 // emptiness must mean "no observations", not "no retained items"
101 return total_weight == 0;
102}
103
104template<typename T, typename W, typename H, typename E, typename A>
106 return map.get_num_active();
107}
108
109template<typename T, typename W, typename H, typename E, typename A>
111 return total_weight;
112}
113
114template<typename T, typename W, typename H, typename E, typename A>
116 // if item is tracked estimate = weight + offset, otherwise 0
117 const W weight = map.get(item);
118 if (weight > 0) { return weight + offset; }
119 return 0;
120}
121
122template<typename T, typename W, typename H, typename E, typename A>
124 return map.get(item);
125}
126
127template<typename T, typename W, typename H, typename E, typename A>
129 return map.get(item) + offset;
130}
131
132template<typename T, typename W, typename H, typename E, typename A>
136
137template<typename T, typename W, typename H, typename E, typename A>
139 return EPSILON_FACTOR / (1 << map.get_lg_max_size());
140}
141
142template<typename T, typename W, typename H, typename E, typename A>
144 return EPSILON_FACTOR / (1 << lg_max_map_size);
145}
146
147template<typename T, typename W, typename H, typename E, typename A>
148double frequent_items_sketch<T, W, H, E, A>::get_apriori_error(uint8_t lg_max_map_size, W estimated_total_weight) {
149 return get_epsilon(lg_max_map_size) * estimated_total_weight;
150}
151
152
153template<typename T, typename W, typename H, typename E, typename A>
155 return get_frequent_items(err_type, get_maximum_error());
156}
157
158template<typename T, typename W, typename H, typename E, typename A>
159auto frequent_items_sketch<T, W, H, E, A>::get_frequent_items(frequent_items_error_type err_type, W threshold) const -> vector_row {
160 vector_row items(map.get_allocator());
161 for (auto it: map) {
162 const W lb = it.second;
163 const W ub = it.second + offset;
164 if ((err_type == NO_FALSE_NEGATIVES && ub > threshold) || (err_type == NO_FALSE_POSITIVES && lb > threshold)) {
165 items.push_back(row(&it.first, it.second, offset));
166 }
167 }
168 // sort by estimate in descending order
169 std::sort(items.begin(), items.end(), [](row a, row b){ return a.get_estimate() > b.get_estimate(); });
170 return items;
171}
172
173template<typename T, typename W, typename H, typename E, typename A>
174template<typename SerDe>
175void frequent_items_sketch<T, W, H, E, A>::serialize(std::ostream& os, const SerDe& sd) const {
176 const uint8_t preamble_longs = is_empty() ? PREAMBLE_LONGS_EMPTY : PREAMBLE_LONGS_NONEMPTY;
177 write(os, preamble_longs);
178 const uint8_t serial_version = SERIAL_VERSION;
179 write(os, serial_version);
180 const uint8_t family = FAMILY_ID;
181 write(os, family);
182 const uint8_t lg_max_size = map.get_lg_max_size();
183 write(os, lg_max_size);
184 const uint8_t lg_cur_size = map.get_lg_cur_size();
185 write(os, lg_cur_size);
186 const uint8_t flags_byte(
187 (is_empty() ? 1 << flags::IS_EMPTY_1 : 0)
188 | (is_empty() ? 1 << flags::IS_EMPTY_2 : 0)
189 );
190 write(os, flags_byte);
191 const uint16_t unused16 = 0;
192 write(os, unused16);
193 if (!is_empty()) {
194 const uint32_t num_items = map.get_num_active();
195 write(os, num_items);
196 const uint32_t unused32 = 0;
197 write(os, unused32);
198 write(os, total_weight);
199 write(os, offset);
200
201 // copy active items and their weights to use batch serialization;
202 // the vectors release the copies if a copy or the serde throws.
203 // a non-empty sketch can have no active items (e.g. after a purge)
204 if (num_items > 0) {
205 using AllocW = typename std::allocator_traits<A>::template rebind_alloc<W>;
206 std::vector<W, AllocW> weights(map.get_allocator());
207 weights.reserve(num_items);
208 std::vector<T, A> items(map.get_allocator());
209 items.reserve(num_items);
210 for (auto it: map) {
211 items.push_back(it.first);
212 weights.push_back(it.second);
213 }
214 write(os, weights.data(), sizeof(W) * num_items);
215 sd.serialize(os, items.data(), num_items);
216 }
217 }
218}
219
220template<typename T, typename W, typename H, typename E, typename A>
221template<typename SerDe>
223 if (is_empty()) { return PREAMBLE_LONGS_EMPTY * sizeof(uint64_t); }
224 size_t size = PREAMBLE_LONGS_NONEMPTY * sizeof(uint64_t) + map.get_num_active() * sizeof(W);
225 for (auto it: map) size += sd.size_of_item(it.first);
226 return size;
227}
228
229template<typename T, typename W, typename H, typename E, typename A>
230template<typename SerDe>
231auto frequent_items_sketch<T, W, H, E, A>::serialize(unsigned header_size_bytes, const SerDe& sd) const -> vector_bytes {
232 const size_t size = header_size_bytes + get_serialized_size_bytes(sd);
233 vector_bytes bytes(size, 0, map.get_allocator());
234 uint8_t* ptr = bytes.data() + header_size_bytes;
235 uint8_t* end_ptr = bytes.data() + size;
236
237 const uint8_t preamble_longs = is_empty() ? PREAMBLE_LONGS_EMPTY : PREAMBLE_LONGS_NONEMPTY;
238 ptr += copy_to_mem(preamble_longs, ptr);
239 const uint8_t serial_version = SERIAL_VERSION;
240 ptr += copy_to_mem(serial_version, ptr);
241 const uint8_t family = FAMILY_ID;
242 ptr += copy_to_mem(family, ptr);
243 const uint8_t lg_max_size = map.get_lg_max_size();
244 ptr += copy_to_mem(lg_max_size, ptr);
245 const uint8_t lg_cur_size = map.get_lg_cur_size();
246 ptr += copy_to_mem(lg_cur_size, ptr);
247 const uint8_t flags_byte(
248 (is_empty() ? 1 << flags::IS_EMPTY_1 : 0)
249 | (is_empty() ? 1 << flags::IS_EMPTY_2 : 0)
250 );
251 ptr += copy_to_mem(flags_byte, ptr);
252 ptr += sizeof(uint16_t); // unused
253 if (!is_empty()) {
254 const uint32_t num_items = map.get_num_active();
255 ptr += copy_to_mem(num_items, ptr);
256 ptr += sizeof(uint32_t); // unused
257 ptr += copy_to_mem(total_weight, ptr);
258 ptr += copy_to_mem(offset, ptr);
259
260 // copy active items and their weights to use batch serialization;
261 // the vectors release the copies if a copy or the serde throws.
262 // a non-empty sketch can have no active items (e.g. after a purge)
263 if (num_items > 0) {
264 using AllocW = typename std::allocator_traits<A>::template rebind_alloc<W>;
265 std::vector<W, AllocW> weights(map.get_allocator());
266 weights.reserve(num_items);
267 std::vector<T, A> items(map.get_allocator());
268 items.reserve(num_items);
269 for (auto it: map) {
270 items.push_back(it.first);
271 weights.push_back(it.second);
272 }
273 ptr += copy_to_mem(weights.data(), ptr, sizeof(W) * num_items);
274 const size_t bytes_remaining = end_ptr - ptr;
275 ptr += sd.serialize(ptr, bytes_remaining, items.data(), num_items);
276 }
277 }
278 return bytes;
279}
280
281template<typename T, typename W, typename H, typename E, typename A>
282class frequent_items_sketch<T, W, H, E, A>::items_deleter {
283public:
284 items_deleter(uint32_t num, bool destroy, const A& allocator):
285 allocator_(allocator), num_(num), destroy_(destroy) {}
286 void set_destroy(bool destroy) { destroy_ = destroy; }
287 void operator() (T* ptr) {
288 if (ptr != nullptr) {
289 if (destroy_) {
290 for (uint32_t i = 0; i < num_; ++i) ptr[i].~T();
291 }
292 allocator_.deallocate(ptr, num_);
293 }
294 }
295private:
296 A allocator_;
297 uint32_t num_;
298 bool destroy_;
299};
300
301template<typename T, typename W, typename H, typename E, typename A>
302template<typename SerDe>
304 const SerDe& sd, const E& equal, const A& allocator) {
305 const auto preamble_longs = read<uint8_t>(is);
306 const auto serial_version = read<uint8_t>(is);
307 const auto family_id = read<uint8_t>(is);
308 const auto lg_max_size = read<uint8_t>(is);
309 const auto lg_cur_size = read<uint8_t>(is);
310 const auto flags_byte = read<uint8_t>(is);
311 read<uint16_t>(is); // unused
312
313 check_preamble_longs(preamble_longs, flags_byte);
314 const bool is_empty = preamble_longs == PREAMBLE_LONGS_EMPTY;
315 check_serial_version(serial_version);
316 check_family_id(family_id);
317 check_size(lg_cur_size, lg_max_size);
318
319 frequent_items_sketch sketch(lg_max_size, lg_cur_size, equal, allocator);
320 if (!is_empty) {
321 const auto num_items = read<uint32_t>(is);
322 read<uint32_t>(is); // unused
323 const auto total_weight = read<W>(is);
324 const auto offset = read<W>(is);
325 check_total_weight(total_weight);
326
327 // batch deserialization with intermediate array of items and weights
328 using AllocW = typename std::allocator_traits<A>::template rebind_alloc<W>;
329 std::vector<W, AllocW> weights(num_items, 0, allocator);
330 read(is, weights.data(), sizeof(W) * num_items);
331 A alloc(allocator);
332 std::unique_ptr<T, items_deleter> items(alloc.allocate(num_items), items_deleter(num_items, false, alloc));
333 sd.deserialize(is, items.get(), num_items);
334 items.get_deleter().set_destroy(true); // serde did not throw, so the items must be constructed
335 for (uint32_t i = 0; i < num_items; i++) {
336 sketch.update(std::move(items.get()[i]), weights[i]);
337 }
338 sketch.total_weight = total_weight;
339 sketch.offset = offset;
340 }
341 if (!is.good()) { throw std::runtime_error("error reading from std::istream"); }
342 return sketch;
343}
344
345template<typename T, typename W, typename H, typename E, typename A>
346template<typename SerDe>
348 const SerDe& sd, const E& equal, const A& allocator) {
349 ensure_minimum_memory(size, 8);
350 const char* ptr = static_cast<const char*>(bytes);
351 const char* base = static_cast<const char*>(bytes);
352 uint8_t preamble_longs;
353 ptr += copy_from_mem(ptr, preamble_longs);
354 uint8_t serial_version;
355 ptr += copy_from_mem(ptr, serial_version);
356 uint8_t family_id;
357 ptr += copy_from_mem(ptr, family_id);
358 uint8_t lg_max_size;
359 ptr += copy_from_mem(ptr, lg_max_size);
360 uint8_t lg_cur_size;
361 ptr += copy_from_mem(ptr, lg_cur_size);
362 uint8_t flags_byte;
363 ptr += copy_from_mem(ptr, flags_byte);
364 ptr += sizeof(uint16_t); // unused
365
366 check_preamble_longs(preamble_longs, flags_byte);
367 const bool is_empty = preamble_longs == PREAMBLE_LONGS_EMPTY;
368 check_serial_version(serial_version);
369 check_family_id(family_id);
370 check_size(lg_cur_size, lg_max_size);
371 ensure_minimum_memory(size, preamble_longs * sizeof(uint64_t));
372
373 frequent_items_sketch sketch(lg_max_size, lg_cur_size, equal, allocator);
374 if (!is_empty) {
375 uint32_t num_items;
376 ptr += copy_from_mem(ptr, num_items);
377 ptr += sizeof(uint32_t); // unused
378 W total_weight;
379 ptr += copy_from_mem(ptr, total_weight);
380 W offset;
381 ptr += copy_from_mem(ptr, offset);
382 check_total_weight(total_weight);
383
384 ensure_minimum_memory(size, ptr - base + (sizeof(W) * num_items));
385 // batch deserialization with intermediate array of items and weights
386 using AllocW = typename std::allocator_traits<A>::template rebind_alloc<W>;
387 std::vector<W, AllocW> weights(num_items, 0, allocator);
388 ptr += copy_from_mem(ptr, weights.data(), sizeof(W) * num_items);
389 A alloc(allocator);
390 std::unique_ptr<T, items_deleter> items(alloc.allocate(num_items), items_deleter(num_items, false, alloc));
391 const size_t bytes_remaining = size - (ptr - base);
392 ptr += sd.deserialize(ptr, bytes_remaining, items.get(), num_items);
393 items.get_deleter().set_destroy(true); // serde did not throw, so the items must be constructed
394 for (uint32_t i = 0; i < num_items; i++) {
395 sketch.update(std::move(items.get()[i]), weights[i]);
396 }
397
398 sketch.total_weight = total_weight;
399 sketch.offset = offset;
400 }
401 return sketch;
402}
403
404template<typename T, typename W, typename H, typename E, typename A>
405void frequent_items_sketch<T, W, H, E, A>::check_preamble_longs(uint8_t preamble_longs, uint8_t flags_byte) {
406 if (preamble_longs != PREAMBLE_LONGS_EMPTY && preamble_longs != PREAMBLE_LONGS_NONEMPTY) {
407 throw std::invalid_argument("Possible corruption: preamble longs must be " + std::to_string(PREAMBLE_LONGS_EMPTY)
408 + " or " + std::to_string(PREAMBLE_LONGS_NONEMPTY) + ": " + std::to_string(preamble_longs));
409 }
410 const bool empty_flag = (flags_byte & ((1 << flags::IS_EMPTY_1) | (1 << flags::IS_EMPTY_2))) != 0;
411 if (empty_flag != (preamble_longs == PREAMBLE_LONGS_EMPTY)) {
412 throw std::invalid_argument("Possible corruption: empty flag does not match preamble longs: flags "
413 + std::to_string(flags_byte) + ", preamble longs " + std::to_string(preamble_longs));
414 }
415}
416
417template<typename T, typename W, typename H, typename E, typename A>
418void frequent_items_sketch<T, W, H, E, A>::check_total_weight(W total_weight) {
419 // written as !(x > 0) to also reject NaN
420 if (!(total_weight > 0)) {
421 throw std::invalid_argument("Possible corruption: total weight of a non-empty sketch must be positive");
422 }
423}
424
425template<typename T, typename W, typename H, typename E, typename A>
426void frequent_items_sketch<T, W, H, E, A>::check_serial_version(uint8_t serial_version) {
427 if (serial_version != SERIAL_VERSION) {
428 throw std::invalid_argument("Possible corruption: serial version must be " + std::to_string(SERIAL_VERSION) + ": " + std::to_string(serial_version));
429 }
430}
431
432template<typename T, typename W, typename H, typename E, typename A>
433void frequent_items_sketch<T, W, H, E, A>::check_family_id(uint8_t family_id) {
434 if (family_id != FAMILY_ID) {
435 throw std::invalid_argument("Possible corruption: family ID must be " + std::to_string(FAMILY_ID) + ": " + std::to_string(family_id));
436 }
437}
438
439template<typename T, typename W, typename H, typename E, typename A>
440void frequent_items_sketch<T, W, H, E, A>::check_size(uint8_t lg_cur_size, uint8_t lg_max_size) {
441 if (lg_cur_size > lg_max_size) {
442 throw std::invalid_argument("Possible corruption: expected lg_cur_size <= lg_max_size: " + std::to_string(lg_cur_size) + " <= " + std::to_string(lg_max_size));
443 }
444 if (lg_cur_size < LG_MIN_MAP_SIZE) {
445 throw std::invalid_argument("Possible corruption: lg_cur_size must not be less than " + std::to_string(LG_MIN_MAP_SIZE) + ": " + std::to_string(lg_cur_size));
446 }
447}
448
449template<typename T, typename W, typename H, typename E, typename A>
450string<A> frequent_items_sketch<T, W, H, E, A>::to_string(bool print_items) const {
451 // Using a temporary stream for implementation here does not comply with AllocatorAwareContainer requirements.
452 // The stream does not support passing an allocator instance, and alternatives are complicated.
453 std::ostringstream os;
454 os << "### Frequent items sketch summary:" << std::endl;
455 os << " lg cur map size : " << (int) map.get_lg_cur_size() << std::endl;
456 os << " lg max map size : " << (int) map.get_lg_max_size() << std::endl;
457 os << " num active items : " << get_num_active_items() << std::endl;
458 os << " total weight : " << get_total_weight() << std::endl;
459 os << " max error : " << get_maximum_error() << std::endl;
460 os << "### End sketch summary" << std::endl;
461 if (print_items) {
462 vector_row items;
463 for (auto it: map) {
464 items.push_back(row(&it.first, it.second, offset));
465 }
466 // sort by estimate in descending order
467 std::sort(items.begin(), items.end(), [](row a, row b){ return a.get_estimate() > b.get_estimate(); });
468 os << "### Items in descending order by estimate" << std::endl;
469 os << " item, estimate, lower bound, upper bound" << std::endl;
470 for (auto it: items) {
471 os << " " << it.get_item() << ", " << it.get_estimate() << ", "
472 << it.get_lower_bound() << ", " << it.get_upper_bound() << std::endl;
473 }
474 os << "### End items" << std::endl;
475 }
476 return string<A>(os.str().c_str(), map.get_allocator());
477}
478
479// version for integral signed type
480template<typename T, typename W, typename H, typename E, typename A>
481template<typename WW, typename std::enable_if<std::is_integral<WW>::value && std::is_signed<WW>::value, int>::type>
482void frequent_items_sketch<T, W, H, E, A>::check_weight(WW weight) {
483 if (weight < 0) {
484 throw std::invalid_argument("weight must be non-negative");
485 }
486}
487
488// version for integral unsigned type - no-op
489template<typename T, typename W, typename H, typename E, typename A>
490template<typename WW, typename std::enable_if<std::is_integral<WW>::value && std::is_unsigned<WW>::value, int>::type>
491void frequent_items_sketch<T, W, H, E, A>::check_weight(WW) {}
492
493// version for floating point type
494template<typename T, typename W, typename H, typename E, typename A>
495template<typename WW, typename std::enable_if<std::is_floating_point<WW>::value, int>::type>
496void frequent_items_sketch<T, W, H, E, A>::check_weight(WW weight) {
497 if (weight < 0) {
498 throw std::invalid_argument("weight must be non-negative");
499 }
500 if (std::isnan(weight)) {
501 throw std::invalid_argument("weight must be a valid number");
502 }
503 if (std::isinf(weight)) {
504 throw std::invalid_argument("weight must be finite");
505 }
506}
507
508}
509
510#endif
Row in the output from get_frequent_items.
Definition frequent_items_sketch.hpp:355
Frequent Items sketch.
Definition frequent_items_sketch.hpp:60
vector_row get_frequent_items(frequent_items_error_type err_type) const
Returns an array of rows that include frequent items, estimates, upper and lower bounds given an erro...
frequent_items_sketch(uint8_t lg_max_map_size, uint8_t lg_start_map_size=LG_MIN_MAP_SIZE, const E &equal=E(), const A &allocator=A())
Construct this sketch with parameters lg_max_map_size and lg_start_map_size.
Definition frequent_items_sketch_impl.hpp:38
W get_upper_bound(const T &item) const
Returns the guaranteed upper bound weight (frequency) of the given item.
Definition frequent_items_sketch_impl.hpp:128
void merge(const frequent_items_sketch &other)
This function merges the other sketch into this one.
Definition frequent_items_sketch_impl.hpp:69
void serialize(std::ostream &os, const SerDe &sd=SerDe()) const
This method serializes the sketch into a given stream in a binary form.
Definition frequent_items_sketch_impl.hpp:175
bool is_empty() const
A sketch is empty if it has not been updated with any positive weight.
Definition frequent_items_sketch_impl.hpp:98
string< A > to_string(bool print_items=false) const
Returns a human readable summary of this sketch.
Definition frequent_items_sketch_impl.hpp:450
void update(const T &item, W weight=1)
Update this sketch with an item and a positive weight (frequency count).
Definition frequent_items_sketch_impl.hpp:53
static double get_apriori_error(uint8_t lg_max_map_size, W estimated_total_weight)
Returns the estimated a priori error given the max_map_size for the sketch and the estimated_total_st...
Definition frequent_items_sketch_impl.hpp:148
W get_total_weight() const
Returns the sum of the weights (frequencies) in the stream seen so far by the sketch.
Definition frequent_items_sketch_impl.hpp:110
double get_epsilon() const
Returns epsilon value of this sketch.
Definition frequent_items_sketch_impl.hpp:138
size_t get_serialized_size_bytes(const SerDe &sd=SerDe()) const
Computes size needed to serialize the current state of the sketch.
Definition frequent_items_sketch_impl.hpp:222
W get_maximum_error() const
Definition frequent_items_sketch_impl.hpp:133
W get_estimate(const T &item) const
Returns the estimate of the weight (frequency) of the given item.
Definition frequent_items_sketch_impl.hpp:115
static frequent_items_sketch deserialize(std::istream &is, const SerDe &sd=SerDe(), const E &equal=E(), const A &allocator=A())
This method deserializes a sketch from a given stream.
void reset()
Resets this sketch to the empty state, as if newly constructed.
Definition frequent_items_sketch_impl.hpp:91
W get_lower_bound(const T &item) const
Returns the guaranteed lower bound weight (frequency) of the given item.
Definition frequent_items_sketch_impl.hpp:123
uint32_t get_num_active_items() const
Definition frequent_items_sketch_impl.hpp:105
DataSketches namespace.
Definition binomial_bounds.hpp:38
frequent_items_error_type
Frequent items error type.
Definition frequent_items_sketch.hpp:36
@ NO_FALSE_NEGATIVES
include an item in the result list if get_upper_bound(item) > threshold
Definition frequent_items_sketch.hpp:38
@ NO_FALSE_POSITIVES
include an item in the result list if get_lower_bound(item) > threshold
Definition frequent_items_sketch.hpp:37