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 4db94e8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 96 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
23 changes: 19 additions & 4 deletions 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,14 @@

namespace seqan::hibf
{

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

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 Expand Up @@ -249,15 +256,15 @@ class interleaved_bloom_filter : private seqan::hibf::bit_vector
*
* \include test/snippet/ibf/interleaved_bloom_filter_emplace.cpp
*/
void emplace(size_t const value, bin_index const bin) noexcept;
[[gnu::always_inline]] void emplace(size_t const value, bin_index const bin) noexcept;

/*!\brief Inserts a value into a specific bin and returns whether the value already existed.
* \param[in] value The raw numeric value to process.
* \param[in] bin The bin index to insert into.
* \returns `true` if the value already existed, `false` otherwise.
* \sa seqan::hibf::interleaved_bloom_filter::emplace
*/
[[nodiscard]] bool emplace_exists(size_t const value, bin_index const bin) noexcept;
[[nodiscard, gnu::always_inline]] bool emplace_exists(size_t const value, bin_index const bin) noexcept;

/*!\brief Clears a specific bin.
* \param[in] bin The bin index to clear.
Expand Down Expand Up @@ -495,7 +502,7 @@ class interleaved_bloom_filter::membership_agent_type
* Concurrent invocations of this function are not thread safe, please create a
* seqan::hibf::interleaved_bloom_filter::membership_agent_type for each thread.
*/
[[nodiscard]] bit_vector const & bulk_contains(size_t const value) & noexcept;
[[nodiscard, gnu::always_inline]] bit_vector const & bulk_contains(size_t const value) & noexcept;

// `bulk_contains` cannot be called on a temporary, since the object the returned reference points to
// is immediately destroyed.
Expand Down Expand Up @@ -616,4 +623,12 @@ class interleaved_bloom_filter::counting_agent_type
//!\}
};

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

} // namespace seqan::hibf

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

#include <hibf/config.hpp>
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
26 changes: 14 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 @@ -193,16 +199,8 @@ 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
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 +289,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.

0 comments on commit 4db94e8

Please sign in to comment.