From 7214d0108a66c6b46603cd57055ac870ccadf4a5 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Thu, 20 Jun 2024 22:58:17 +0200 Subject: [PATCH] const saving in visit --- external/pthash | 2 +- include/buckets.hpp | 17 +++++++++++++---- include/dictionary.hpp | 28 +++++++++++++++++++--------- include/ef_sequence.hpp | 19 ++++++++++++++----- include/minimizers.hpp | 5 +++++ include/skew_index.hpp | 21 ++++++++++++++++----- include/weights.hpp | 16 +++++++++++++--- 7 files changed, 81 insertions(+), 27 deletions(-) diff --git a/external/pthash b/external/pthash index 2ee455f..c977ec4 160000 --- a/external/pthash +++ b/external/pthash @@ -1 +1 @@ -Subproject commit 2ee455f7ce1cb3f1f99242b4ffdbe28ed72a7f7f +Subproject commit c977ec4a22c202e72de6a23bc111960ce99237cc diff --git a/include/buckets.hpp b/include/buckets.hpp index a618ee1..880c7e4 100644 --- a/include/buckets.hpp +++ b/include/buckets.hpp @@ -255,12 +255,14 @@ struct buckets { 8 * (offsets.bytes() + strings.bytes()); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(pieces); - visitor.visit(num_super_kmers_before_bucket); - visitor.visit(offsets); - visitor.visit(strings); + visit_impl(visitor, *this); } ef_sequence pieces; @@ -269,6 +271,13 @@ struct buckets { pthash::bit_vector strings; private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.pieces); + visitor.visit(t.num_super_kmers_before_bucket); + visitor.visit(t.offsets); + visitor.visit(t.strings); + } bool is_valid(lookup_result res) const { return (res.contig_size != constants::invalid_uint64 and res.kmer_id_in_contig < res.contig_size) and diff --git a/include/dictionary.hpp b/include/dictionary.hpp index 974a44d..1c97701 100644 --- a/include/dictionary.hpp +++ b/include/dictionary.hpp @@ -117,20 +117,30 @@ struct dictionary { void print_space_breakdown() const; void compute_statistics() const; + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_size); - visitor.visit(m_seed); - visitor.visit(m_k); - visitor.visit(m_m); - visitor.visit(m_canonical_parsing); - visitor.visit(m_minimizers); - visitor.visit(m_buckets); - visitor.visit(m_skew_index); - visitor.visit(m_weights); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_size); + visitor.visit(t.m_seed); + visitor.visit(t.m_k); + visitor.visit(t.m_m); + visitor.visit(t.m_canonical_parsing); + visitor.visit(t.m_minimizers); + visitor.visit(t.m_buckets); + visitor.visit(t.m_skew_index); + visitor.visit(t.m_weights); + } + uint64_t m_size; uint64_t m_seed; uint16_t m_k; diff --git a/include/ef_sequence.hpp b/include/ef_sequence.hpp index 56682ac..15db0c7 100644 --- a/include/ef_sequence.hpp +++ b/include/ef_sequence.hpp @@ -186,16 +186,25 @@ struct ef_sequence { m_high_bits_d0.bytes() + m_low_bits.bytes()); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_universe); - visitor.visit(m_high_bits); - visitor.visit(m_high_bits_d1); - visitor.visit(m_high_bits_d0); - visitor.visit(m_low_bits); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_universe); + visitor.visit(t.m_high_bits); + visitor.visit(t.m_high_bits_d1); + visitor.visit(t.m_high_bits_d0); + visitor.visit(t.m_low_bits); + } uint64_t m_universe; pthash::bit_vector m_high_bits; pthash::darray1 m_high_bits_d1; diff --git a/include/minimizers.hpp b/include/minimizers.hpp index f58cb90..452c7e2 100644 --- a/include/minimizers.hpp +++ b/include/minimizers.hpp @@ -40,6 +40,11 @@ struct minimizers { uint64_t size() const { return m_mphf.num_keys(); } uint64_t num_bits() const { return m_mphf.num_bits(); } + template + void visit(Visitor& visitor) const { + visitor.visit(m_mphf); + } + template void visit(Visitor& visitor) { visitor.visit(m_mphf); diff --git a/include/skew_index.hpp b/include/skew_index.hpp index c1ff603..57f37ac 100644 --- a/include/skew_index.hpp +++ b/include/skew_index.hpp @@ -44,13 +44,14 @@ struct skew_index { return n; } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(min_log2); - visitor.visit(max_log2); - visitor.visit(log2_max_num_super_kmers_in_bucket); - visitor.visit(mphfs); - visitor.visit(positions); + visit_impl(visitor, *this); } uint16_t min_log2; @@ -58,6 +59,16 @@ struct skew_index { uint32_t log2_max_num_super_kmers_in_bucket; std::vector mphfs; std::vector positions; + +private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.min_log2); + visitor.visit(t.max_log2); + visitor.visit(t.log2_max_num_super_kmers_in_bucket); + visitor.visit(t.mphfs); + visitor.visit(t.positions); + } }; } // namespace sshash \ No newline at end of file diff --git a/include/weights.hpp b/include/weights.hpp index 471b0ba..43ee415 100644 --- a/include/weights.hpp +++ b/include/weights.hpp @@ -168,14 +168,24 @@ struct weights { << " [bits/kmer]\n"; } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_weight_interval_values); - visitor.visit(m_weight_interval_lengths); - visitor.visit(m_weight_dictionary); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_weight_interval_values); + visitor.visit(t.m_weight_interval_lengths); + visitor.visit(t.m_weight_dictionary); + } + pthash::compact_vector m_weight_interval_values; ef_sequence m_weight_interval_lengths; pthash::compact_vector m_weight_dictionary;