20#ifndef THETA_HELPERS_HPP_
21#define THETA_HELPERS_HPP_
29#include "theta_constants.hpp"
30#include "theta_comparators.hpp"
52template<
typename ExtractKey,
typename Entry,
typename Allocator>
53static uint64_t trim_to_nominal(std::vector<Entry, Allocator>& entries, uint32_t nominal_size, uint64_t theta) {
54 if (entries.size() <= nominal_size)
return theta;
55 std::nth_element(entries.begin(), entries.begin() + nominal_size, entries.end(), compare_by_key<ExtractKey>());
56 const uint64_t new_theta = ExtractKey()(entries[nominal_size]);
57 entries.erase(entries.begin() + nominal_size, entries.end());
58 entries.shrink_to_fit();
63static void check_value(T actual, T expected,
const char* description) {
64 if (actual != expected) {
65 throw std::invalid_argument(std::string(description) +
" mismatch: expected " + std::to_string(expected) +
", actual " + std::to_string(actual));
72 static void check_serial_version(uint8_t actual, uint8_t expected) {
73 check_value(actual, expected,
"serial version");
75 static void check_sketch_family(uint8_t actual, uint8_t expected) {
76 check_value(actual, expected,
"sketch family");
78 static void check_sketch_type(uint8_t actual, uint8_t expected) {
79 check_value(actual, expected,
"sketch type");
81 static void check_seed_hash(uint16_t actual, uint16_t expected) {
82 check_value(actual, expected,
"seed hash");
87class theta_build_helper{
91 static uint64_t starting_theta_from_p(
float p) {
96 static uint8_t starting_sub_multiple(uint8_t lg_tgt, uint8_t lg_min, uint8_t lg_rf) {
97 return (lg_tgt <= lg_min) ? lg_min : (lg_rf == 0) ? lg_tgt : ((lg_tgt - lg_min) % lg_rf) + lg_min;
const uint64_t MAX_THETA
max theta - signed max for compatibility with Java
Definition theta_constants.hpp:36
DataSketches namespace.
Definition binomial_bounds.hpp:38