Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MISC] Make HIBF agents copyable #211

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions include/hibf/hierarchical_interleaved_bloom_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class hierarchical_interleaved_bloom_filter::membership_agent_type
{
private:
//!\brief A pointer to the augmented hierarchical_interleaved_bloom_filter.
hierarchical_interleaved_bloom_filter const * const hibf_ptr{nullptr};
hierarchical_interleaved_bloom_filter const * hibf_ptr{nullptr};

//!\brief Helper for recursive membership querying.
template <std::ranges::forward_range value_range_t>
Expand Down Expand Up @@ -305,12 +305,12 @@ class hierarchical_interleaved_bloom_filter::membership_agent_type
/*!\name Constructors, destructor and assignment
* \{
*/
membership_agent_type() = default; //!< Defaulted.
membership_agent_type(membership_agent_type const &) = default; //!< Defaulted.
membership_agent_type & operator=(membership_agent_type const &) = delete; //!< Deleted. hibf_ptr is const.
membership_agent_type(membership_agent_type &&) = default; //!< Defaulted.
membership_agent_type & operator=(membership_agent_type &&) = delete; //!< Deleted. hibf_ptr is const.
~membership_agent_type() = default; //!< Defaulted.
membership_agent_type() = default; //!< Defaulted.
membership_agent_type(membership_agent_type const &) = default; //!< Defaulted.
membership_agent_type & operator=(membership_agent_type const &) = default; //!< Defaulted.
membership_agent_type(membership_agent_type &&) = default; //!< Defaulted.
membership_agent_type & operator=(membership_agent_type &&) = default; //!< Defaulted.
~membership_agent_type() = default; //!< Defaulted.

/*!\brief Construct a membership_agent_type for an existing hierarchical_interleaved_bloom_filter.
* \private
Expand Down Expand Up @@ -401,7 +401,7 @@ class hierarchical_interleaved_bloom_filter::counting_agent_type
{
private:
//!\brief A pointer to the augmented hierarchical_interleaved_bloom_filter.
hierarchical_interleaved_bloom_filter const * const hibf_ptr{nullptr};
hierarchical_interleaved_bloom_filter const * hibf_ptr{nullptr};

//!\brief Helper for recursive bulk counting.
template <std::ranges::forward_range value_range_t>
Expand Down Expand Up @@ -440,12 +440,12 @@ class hierarchical_interleaved_bloom_filter::counting_agent_type
/*!\name Constructors, destructor and assignment
* \{
*/
counting_agent_type() = default; //!< Defaulted.
counting_agent_type(counting_agent_type const &) = default; //!< Defaulted.
counting_agent_type & operator=(counting_agent_type const &) = delete; //!< Deleted. hibf_ptr is const.
counting_agent_type(counting_agent_type &&) = default; //!< Defaulted.
counting_agent_type & operator=(counting_agent_type &&) = delete; //!< Deleted. hibf_ptr is const.
~counting_agent_type() = default; //!< Defaulted.
counting_agent_type() = default; //!< Defaulted.
counting_agent_type(counting_agent_type const &) = default; //!< Defaulted.
counting_agent_type & operator=(counting_agent_type const &) = default; //!< Defaulted.
counting_agent_type(counting_agent_type &&) = default; //!< Defaulted.
counting_agent_type & operator=(counting_agent_type &&) = default; //!< Defaulted.
~counting_agent_type() = default; //!< Defaulted.

/*!\brief Construct a counting_agent_type for an existing hierarchical_interleaved_bloom_filter.
* \private
Expand Down
37 changes: 37 additions & 0 deletions test/unit/hibf/hierarchical_interleaved_bloom_filter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,43 @@ TEST(hibf_test, counting_agent_different_bins)
}
}

TEST(hibf_test, copy_agents)
{
std::vector<std::vector<size_t>> hashes{{1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u}, {1u, 2u, 3u, 4u, 5u}};

seqan::hibf::config config{.input_fn =
[&](size_t const num, seqan::hibf::insert_iterator it)
{
for (auto const hash : hashes[num])
it = hash;
},
.number_of_user_bins = 2};

seqan::hibf::hierarchical_interleaved_bloom_filter hibf{config};
std::vector<size_t> query{1u, 2u, 3u, 4u, 5u};

{
auto membership_agent1 = hibf.membership_agent();
auto membership_agent2 = membership_agent1;

auto & result1 = membership_agent1.membership_for(query, 2u);
membership_agent1.sort_results();
auto & result2 = membership_agent2.membership_for(query, 6u);
membership_agent2.sort_results();
EXPECT_RANGE_EQ(result1, (std::vector<size_t>{0u, 1u}));
EXPECT_RANGE_EQ(result2, (std::vector<size_t>{}));
}
{
auto counting_agent1 = hibf.counting_agent();
auto counting_agent2 = counting_agent1;
auto & result1 = counting_agent1.bulk_count(query, 1u);
auto & result2 = counting_agent2.bulk_count(query, 6u);
ASSERT_EQ(result1.size(), result2.size());
EXPECT_RANGE_EQ(result1, (std::vector<size_t>{5u, 5u}));
EXPECT_RANGE_EQ(result2, (std::vector<size_t>{0u, 0u}));
}
}

TEST(hibf_test, serialisation)
{
// range of range of sequences
Expand Down
32 changes: 32 additions & 0 deletions test/unit/hibf/interleaved_bloom_filter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,38 @@ TEST(ibf_test, increase_bin_number_to)
}
}

TEST(ibf_test, copy_agents)
{
// 1. Construct and emplace
seqan::hibf::interleaved_bloom_filter ibf{seqan::hibf::bin_count{64u},
seqan::hibf::bin_size{1024u},
seqan::hibf::hash_function_count{2u}};

for (size_t bin_idx : std::views::iota(0, 64))
ibf.emplace(0u, seqan::hibf::bin_index{bin_idx});

{
auto membership_agent1 = ibf.membership_agent();
auto membership_agent2 = membership_agent1;

auto & result1 = membership_agent1.bulk_contains(0u);
auto & result2 = membership_agent2.bulk_contains(1u);
ASSERT_EQ(result1.size(), result2.size());

EXPECT_TRUE(result1.all());
EXPECT_TRUE(result2.none());
}
{
auto counting_agent1 = ibf.counting_agent();
auto counting_agent2 = counting_agent1;
auto & result1 = counting_agent1.bulk_count(std::vector<uint64_t>{0u});
auto & result2 = counting_agent2.bulk_count(std::vector<uint64_t>{1u});
ASSERT_EQ(result1.size(), result2.size());
EXPECT_RANGE_EQ(result1, std::vector<size_t>(64u, 1u));
EXPECT_RANGE_EQ(result2, std::vector<size_t>(64u, 0u));
}
}

TEST(ibf_test, serialisation)
{
seqan::hibf::interleaved_bloom_filter ibf{seqan::hibf::bin_count{128u},
Expand Down
Loading