Skip to content

Commit

Permalink
[FEATURE] Make hll and minhash sketches cerealisable (#216)
Browse files Browse the repository at this point in the history
* wip

* add vector

* Update include/hibf/sketch/hyperloglog.hpp

---------

Co-authored-by: Enrico Seiler <[email protected]>
  • Loading branch information
smehringer and eseiler authored Aug 19, 2024
1 parent 842f780 commit f1d1d60
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit f1d1d60

Please sign in to comment.