Skip to content

Commit

Permalink
[WIP] Header only and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Oct 23, 2024
1 parent 2ed20d8 commit b80ff97
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 93 deletions.
2 changes: 1 addition & 1 deletion include/hibf/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <cereal/access.hpp> // for access
#include <cereal/cereal.hpp> // for make_nvp, CEREAL_NVP

#include <hibf/misc/insert_iterator.hpp> // for insert_iterator
#include <hibf/misc/insert_iterator.hpp>
#include <hibf/platform.hpp>

namespace seqan::hibf
Expand Down
5 changes: 4 additions & 1 deletion include/hibf/interleaved_bloom_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <cereal/types/base_class.hpp> // for base_class

#include <hibf/cereal/concepts.hpp> // for cereal_archive
#include <hibf/config.hpp> // for config
#include <hibf/contrib/aligned_allocator.hpp> // for aligned_allocator
#include <hibf/misc/bit_vector.hpp> // for bit_vector
#include <hibf/misc/counting_vector.hpp> // for counting_vector
Expand All @@ -33,6 +32,10 @@

namespace seqan::hibf
{

// config.hpp -> misc/insert_iterator.hpp (Needs interleaved_bloom_filter to be a complete class)
struct config;

/*!\brief A strong type that represents the number of bins for the seqan::hibf::interleaved_bloom_filter.
* \ingroup ibf
* \qualifier strong
Expand Down
37 changes: 24 additions & 13 deletions include/hibf/misc/insert_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,15 @@
#include <vector> // for vector

#include <hibf/contrib/robin_hood.hpp> // for unordered_flat_set, hash
#include <hibf/interleaved_bloom_filter.hpp>
#include <hibf/platform.hpp>
#include <hibf/sketch/hyperloglog.hpp>

// IWYU pragma: private, include <hibf/config.hpp>

namespace seqan::hibf
{

// hibf/interleaved_bloom_filter.hpp includes config.hpp, which includes insert_iterator.hpp
// Hence, we need a forward declaration.
class interleaved_bloom_filter;

namespace sketch
{

class hyperloglog;

}

class insert_iterator
{
public:
Expand Down Expand Up @@ -64,10 +55,30 @@ class insert_iterator
type{data_type::ibf}
{}

constexpr insert_iterator(function_t & fun) : ptr{std::addressof(fun)}, type{data_type::function}
explicit constexpr insert_iterator(function_t & fun) : ptr{std::addressof(fun)}, type{data_type::function}
{}

insert_iterator & operator=(uint64_t const value) noexcept;
[[gnu::always_inline, gnu::flatten]] constexpr insert_iterator & operator=(uint64_t const value) noexcept
{
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;
default:
assert(type == data_type::function);
static_cast<function_t *>(ptr)->operator()(value);
}
return *this;
}

[[nodiscard]] constexpr insert_iterator & operator*() noexcept
{
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ set (HIBF_SOURCE_FILES
sketch/compute_sketches.cpp
layout/graph.cpp
layout/hierarchical_binning.cpp
misc/insert_iterator.cpp
misc/print.cpp
sketch/toolbox.cpp
sketch/hyperloglog.cpp
Expand Down
27 changes: 15 additions & 12 deletions src/interleaved_bloom_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
#include <hibf/interleaved_bloom_filter.hpp> // for interleaved_bloom_filter, bin_count, bin_index, bin_size, hash_...
#include <hibf/misc/bit_vector.hpp> // for bit_vector
#include <hibf/misc/divide_and_ceil.hpp> // for divide_and_ceil
#include <hibf/platform.hpp> // for HIBF_COMPILER_IS_GCC
#include <hibf/sketch/compute_sketches.hpp> // for compute_sketches
#include <hibf/sketch/hyperloglog.hpp> // for hyperloglog
#include <hibf/misc/insert_iterator.hpp>
#include <hibf/platform.hpp> // for HIBF_COMPILER_IS_GCC
#include <hibf/sketch/compute_sketches.hpp> // for compute_sketches
#include <hibf/sketch/hyperloglog.hpp> // for hyperloglog

namespace seqan::hibf
{

#if HIBF_COMPILER_IS_GCC
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wattributes"
#endif // HIBF_COMPILER_IS_GCC

interleaved_bloom_filter::interleaved_bloom_filter(seqan::hibf::bin_count bins_,
seqan::hibf::bin_size size,
seqan::hibf::hash_function_count funs)
Expand Down Expand Up @@ -133,12 +139,12 @@ inline auto interleaved_bloom_filter::emplace_impl(size_t const value, bin_index
return exists;
};

void interleaved_bloom_filter::emplace(size_t const value, bin_index const bin) noexcept
[[gnu::always_inline]] void interleaved_bloom_filter::emplace(size_t const value, bin_index const bin) noexcept
{
return emplace_impl<false>(value, bin);
}

bool interleaved_bloom_filter::emplace_exists(size_t const value, bin_index const bin) noexcept
[[gnu::always_inline]] bool interleaved_bloom_filter::emplace_exists(size_t const value, bin_index const bin) noexcept
{
return emplace_impl<true>(value, bin);
}
Expand Down Expand Up @@ -193,16 +199,9 @@ void interleaved_bloom_filter::increase_bin_number_to(seqan::hibf::bin_count con
technical_bins = new_technical_bins;
}

#if HIBF_COMPILER_IS_GCC
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wattributes"
#endif // HIBF_COMPILER_IS_GCC
[[gnu::always_inline]] bit_vector const &
interleaved_bloom_filter::membership_agent_type::bulk_contains(size_t const value) & noexcept
{
#if HIBF_COMPILER_IS_GCC
# pragma GCC diagnostic pop
#endif // HIBF_COMPILER_IS_GCC
assert(ibf_ptr != nullptr);
assert(result_buffer.size() == ibf_ptr->bin_count());

Expand Down Expand Up @@ -291,4 +290,8 @@ interleaved_bloom_filter::membership_agent_type::bulk_contains(size_t const valu
return result_buffer;
}

#if HIBF_COMPILER_IS_GCC
# pragma GCC diagnostic pop
#endif // HIBF_COMPILER_IS_GCC

} // namespace seqan::hibf
65 changes: 0 additions & 65 deletions src/misc/insert_iterator.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <utility> // for move, pair
#include <vector> // for vector

#include <hibf/config.hpp> // for config
#include <hibf/contrib/robin_hood.hpp> // for hash, unordered_map
#include <hibf/contrib/std/chunk_view.hpp> // for chunk, chunk_fn, chunk_view
#include <hibf/contrib/std/detail/adaptor_base.hpp> // for operator|
Expand Down

0 comments on commit b80ff97

Please sign in to comment.