2
0
mirror of https://github.com/boostorg/bloom.git synced 2026-01-27 18:52:10 +00:00
Files
bloom/test/test_insertion.cpp
joaquintides 2592193066 review feedback (#32)
* removed superfluous inline (Alexander Grund)
* made hasher equivalence a precondition for &=/|= (Andrzej Krzemienski)
* documented exception safety guarantees (Andrzej Krzemienski)
* mentioned Bloom filters are called so after Burton H Bloom (Dmitry Arkhipov)
* added warning about OOM for very small FPR (Ivan Matek)
* stressed config chart x axis is capacity/num elements rather than plain capacity (Ivan Matek)
* s/[SIMD] is available/is enabled at compile time (Ivan Matek)
* shut down clang-tidy warnings (Ivan Matek)
* used "set union" for more clarity (Andrzej Krzemienski)
* stressed early on that boost::bloom::filter is _not_ a container (Claudio DeSouza)
* added bulk operations to roadmap (Dmitry Arkhipov)
* added try_insert to roadmap (Konstantin Savvidy)
* added estimated_size to roadmap (Konstantin Savvidy)
* added alternative filters to roadmap (Konstantin Savvidy)
* used <cstdint> instead of <boost/cstdint.hpp> (Rubén Pérez)
* mentioned endianness when serializing filters (Rubén Pérez)
* corrected sloppiness about optimum k determination (Tomer Vromen)
* added run-time specification of k to roadmap (Tomer Vromen)
* added test/CMakeLists.txt (Rubén Pérez)
* added CMake-based testing to GHA (Rubén Pérez) (#8)
* added <boost/bloom.hpp> (Rubén Pérez)
* added Codecov reporting (Rubén Pérez) (#9)
* moved from boost::unordered::hash_is_avalanching to ContainerHash's boost::hash_is_avalanching (Ivan Matek/Peter Dimov)
* added syntax highlighting to code snippets (Rubén Pérez)
* avoided C-style casts in examples (Rubén Pérez)
* added acknowledgements section (Peter Turcan)
* added Getting Started section (Peter Turcan)
* fixed example Jamfile and added example building to CI (Rubén Pérez) (#10)
* added diagram about overlapping vs. non-overlapping subarrays (Rubén Pérez/Ivan Matek/Vinnie Falco)
* made first code snippet self-contained (Rubén Pérez/Peter Turcan)
* added more comments to genome.cpp (Rubén Pérez)
* added support for arrays as blocks (Tomer Vromen) (#24)
* removed emplace (Seth Heeren/Peter Dimov) (#25)
* required the allocator to be of unsigned char (Seth Heeren/Peter Dimov) (#26)
* added compile-time validation of Block types (Rubén Pérez) (#27)
* added value type to displayed filter names in tables (Tomer Vromen) (#28)
* used -march=native rather than -mavx2 (Ivan Matek)
* adopted hash strategy with fastrange plus a separate MCG (Kostas Savvidis/Peter Dimov) (#30)
* several maintenance commits
2025-06-24 23:27:54 +02:00

98 lines
2.2 KiB
C++

/* 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 <boost/core/lightweight_test.hpp>
#include <array>
#include <boost/mp11/algorithm.hpp>
#include <utility>
#include "test_types.hpp"
#include "test_utilities.hpp"
using namespace test_utilities;
template<typename T>
struct multiarg_constructed
{
multiarg_constructed()=default;
template<typename Arg1,typename Arg2,typename... Args>
multiarg_constructed(Arg1&& arg,Arg2&&,Args&&...):
x{std::forward<Arg1>(arg)}{}
multiarg_constructed(const multiarg_constructed&)=delete;
multiarg_constructed(multiarg_constructed&&)=delete;
multiarg_constructed& operator=(const multiarg_constructed&)=default;
operator const T&()const{return x;}
T x;
};
template<typename Functor>
struct transparent:Functor
{
using is_transparent=void;
using Functor::Functor;
};
template<typename Filter,typename ValueFactory>
void test_insertion()
{
using filter=rehash_filter<
revalue_filter<Filter,multiarg_constructed<typename Filter::value_type>>,
transparent<typename Filter::hasher>
>;
using value_type=typename filter::value_type;
filter f(10000);
ValueFactory fac;
{
value_type x{fac(),0};
f.insert(const_cast<value_type&>(x));
BOOST_TEST(f.may_contain(x));
}
{
value_type x{fac(),0};
f.insert(std::move(x));
BOOST_TEST(f.may_contain(x));
}
{
auto x=fac();
f.insert(x); /* transparent insert */
BOOST_TEST(f.may_contain(x));
}
{
std::array<value_type,10> input;
for(auto& x:input)x={fac(),0};
f.insert(input.begin(),input.end());
BOOST_TEST(may_contain(f,input));
}
{
std::initializer_list<value_type> il={{fac(),0},{fac(),0},{fac(),0}};
f.insert(il);
BOOST_TEST(may_contain(f,il));
}
}
struct lambda
{
template<typename T>
void operator()(T)
{
using filter=typename T::type;
using value_type=typename filter::value_type;
test_insertion<filter,value_factory<value_type>>();
}
};
int main()
{
boost::mp11::mp_for_each<identity_test_types>(lambda{});
return boost::report_errors();
}