/* For a given filter type, outputs FPR vs. c = m/n with optimum k. * * Copyright 2025 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * See https://www.boost.org/libs/bloom for library home page. */ #include #include #include #include #include #include #include #include #include #include #include #include template double fpr(std::size_t c) { using value_type=typename Filter::value_type; std::size_t num_elements=(std::size_t)(1000/Filter::fpr_for(1,c)); std::vector data_in,data_out; { boost::detail::splitmix64 rng; boost::unordered_flat_set unique; for(std::size_t i=0;i using filter=boost::bloom::filter,1>; /* change this to your desired c range */ std::size_t c_min=4, c_max=24; /* you may need to change this if optimum k >= k_max */ constexpr std::size_t k_max=20; using fpr_function=std::function; static std::vector fprs=[] { std::vector fprs; using ks=boost::mp11::mp_iota_c; boost::mp11::mp_for_each([&](auto K){ fprs.emplace_back(fpr< ::filter >); }); return fprs; }(); int main() { std::string filter_name= boost::typeindex::type_id< ::filter<666> >().pretty_name(); boost::replace_all(filter_name,"boost::bloom::",""); boost::replace_all(filter_name,"class ",""); boost::replace_all(filter_name,"struct ",""); boost::replace_all(filter_name,"666","K"); std::cout <=k_max){ std::cerr<<"k_max hit, raise it and rerun\n"; return EXIT_FAILURE; } double rn=fprs[ik+1](c); if(rn>=r)break; r=rn; ++ik; } std::cout<