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

[FEATURE] Make hll and minhash sketches cerealisable #216

Merged
merged 3 commits into from
Aug 19, 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
18 changes: 18 additions & 0 deletions include/hibf/sketch/hyperloglog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <iosfwd> // for istream, ostream
#include <vector> // for vector

#include <cereal/cereal.hpp>
#include <cereal/types/vector.hpp>

#include <hibf/contrib/aligned_allocator.hpp> // for aligned_allocator
#include <hibf/platform.hpp>

Expand Down Expand Up @@ -125,6 +128,21 @@ class hyperloglog
double normalization_factor{};
//!\brief Internal data. Also called register in publications.
std::vector<uint8_t, seqan::hibf::contrib::aligned_allocator<uint8_t, 32u>> data{};

friend class cereal::access;

template <typename archive_t>
void serialize(archive_t & archive)
{
uint32_t version{1};
archive(CEREAL_NVP(version));

archive(CEREAL_NVP(bits));
archive(CEREAL_NVP(size));
archive(CEREAL_NVP(rank_mask));
archive(CEREAL_NVP(normalization_factor));
archive(CEREAL_NVP(data));
}
};

} // namespace seqan::hibf::sketch
15 changes: 15 additions & 0 deletions include/hibf/sketch/minhashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <span> // for span
#include <vector> // for vector

#include <cereal/cereal.hpp>

#include <hibf/platform.hpp>

namespace seqan::hibf::sketch
Expand Down Expand Up @@ -59,6 +61,19 @@ struct minhashes

//!\brief Pushes `value` to the heap if it is smaller than the current largest element.
static void push_to_heap_if_smaller(uint64_t const value, std::vector<uint64_t> & heap);

private:
friend class cereal::access;

template <typename archive_t>
void serialize(archive_t & archive)
{
uint32_t version{1};
archive(CEREAL_NVP(version));

// other members are const static currently
archive(CEREAL_NVP(table));
}
};

} // namespace seqan::hibf::sketch
Loading