generated from seqan/library-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
171 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin | ||
// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <cassert> // for assert | ||
#include <cmath> // for ceil, sqrt | ||
#include <functional> // for function | ||
#include <iostream> // for operator<<, basic_ostream, basic_istream, getline, stringstream | ||
#include <sstream> // for basic_stringstream | ||
#include <stdexcept> // for invalid_argument | ||
#include <string> // for char_traits, string | ||
#include <string_view> // for operator==, basic_string_view, string_view | ||
|
||
#include <cereal/archives/json.hpp> // for JSONInputArchive, JSONOutputArchive | ||
#include <cereal/cereal.hpp> // for make_nvp, InputArchive, OutputArchive | ||
|
||
#include <hibf/interleaved_bloom_filter.hpp> | ||
#include <hibf/misc/insert_iterator.hpp> // for insert_iterator | ||
#include <hibf/sketch/hyperloglog.hpp> | ||
|
||
namespace seqan::hibf | ||
{ | ||
|
||
// Inlining std::function produces overhead which affects the other cases. | ||
[[gnu::noinline]] void invoke_without_inlining(void * const ptr, uint64_t const value) | ||
{ | ||
static_cast<typename insert_iterator::function_t *>(ptr)->operator()(value); | ||
} | ||
|
||
#if HIBF_COMPILER_IS_GCC | ||
# pragma GCC diagnostic push | ||
# pragma GCC diagnostic ignored "-Wattributes" | ||
#endif // HIBF_COMPILER_IS_GCC | ||
[[gnu::always_inline]] insert_iterator & insert_iterator::operator=(uint64_t const value) noexcept | ||
{ | ||
#if HIBF_COMPILER_IS_GCC | ||
# pragma GCC diagnostic pop | ||
#endif // HIBF_COMPILER_IS_GCC | ||
assert(ptr != nullptr); | ||
|
||
switch (type) | ||
{ | ||
case data_type::unordered_set: | ||
static_cast<set_t *>(ptr)->emplace(value); | ||
break; | ||
case data_type::sketch: | ||
static_cast<sketch_t *>(ptr)->add(value); | ||
break; | ||
case data_type::ibf: | ||
static_cast<ibf_t *>(ptr)->emplace(value, static_cast<bin_index>(ibf_bin_index)); | ||
break; | ||
case data_type::function: | ||
invoke_without_inlining(ptr, value); | ||
break; | ||
default: // GCOVR_EXCL_LINE | ||
#ifndef NDEBUG | ||
assert(false); // GCOVR_EXCL_LINE | ||
#else | ||
__builtin_unreachable(); | ||
#endif | ||
} | ||
return *this; | ||
} | ||
|
||
} // namespace seqan::hibf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin | ||
// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <gtest/gtest.h> // for Message, TestPartResult, AssertionResult, Test, EXPECT_EQ, Capture... | ||
|
||
#include <hibf/interleaved_bloom_filter.hpp> | ||
#include <hibf/misc/insert_iterator.hpp> | ||
#include <hibf/sketch/hyperloglog.hpp> | ||
#include <hibf/test/expect_range_eq.hpp> // for expect_range_eq, EXPECT_RANGE_EQ | ||
|
||
static constexpr std::array<size_t, 10> values{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
|
||
TEST(insert_iterator_test, unordered_set) | ||
{ | ||
robin_hood::unordered_flat_set<uint64_t> target; | ||
seqan::hibf::insert_iterator it{target}; | ||
std::ranges::copy(values, it); | ||
EXPECT_EQ(target.size(), 10u); | ||
} | ||
|
||
TEST(insert_iterator_test, sketch) | ||
{ | ||
seqan::hibf::sketch::hyperloglog target{5u}; | ||
seqan::hibf::insert_iterator it{target}; | ||
std::ranges::copy(values, it); | ||
EXPECT_NEAR(target.estimate(), 11.99, 0.001); | ||
} | ||
|
||
TEST(insert_iterator_test, ibf) | ||
{ | ||
seqan::hibf::interleaved_bloom_filter target{seqan::hibf::bin_count{8u}, | ||
seqan::hibf::bin_size{8u}, | ||
seqan::hibf::hash_function_count{1u}}; | ||
for (size_t i = 0; i < 3; ++i) | ||
{ | ||
seqan::hibf::insert_iterator it{target, i}; | ||
std::ranges::copy(values, it); | ||
} | ||
|
||
auto agent = target.counting_agent<uint8_t>(); | ||
auto & result = agent.bulk_count(values); | ||
std::vector<uint8_t> const expected{10, 10, 10, 0, 0, 0, 0, 0}; | ||
EXPECT_RANGE_EQ(result, expected); | ||
} | ||
|
||
TEST(insert_iterator_test, function) | ||
{ | ||
robin_hood::unordered_flat_set<uint64_t> target; | ||
std::function<void(uint64_t const)> fun = [&target](size_t const value) | ||
{ | ||
target.emplace(value); | ||
target.emplace((1u + value) * 11u); | ||
}; | ||
seqan::hibf::insert_iterator it{fun}; | ||
std::ranges::copy(values, it); | ||
EXPECT_EQ(target.size(), 20); | ||
} |