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

Use universal visitors for const-ref saving #46

Merged
merged 1 commit into from
Jun 22, 2024
Merged
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
const saving in visit
adamant-pwn committed Jun 22, 2024
commit 7214d0108a66c6b46603cd57055ac870ccadf4a5
17 changes: 13 additions & 4 deletions include/buckets.hpp
Original file line number Diff line number Diff line change
@@ -255,12 +255,14 @@ struct buckets {
8 * (offsets.bytes() + strings.bytes());
}

template <typename Visitor>
void visit(Visitor& visitor) const {
visit_impl(visitor, *this);
}

template <typename Visitor>
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<true> pieces;
@@ -269,6 +271,13 @@ struct buckets {
pthash::bit_vector strings;

private:
template <typename Visitor, typename T>
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
28 changes: 19 additions & 9 deletions include/dictionary.hpp
Original file line number Diff line number Diff line change
@@ -117,20 +117,30 @@ struct dictionary {
void print_space_breakdown() const;
void compute_statistics() const;

template <typename Visitor>
void visit(Visitor& visitor) const {
visit_impl(visitor, *this);
}

template <typename Visitor>
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 <typename Visitor, typename T>
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;
19 changes: 14 additions & 5 deletions include/ef_sequence.hpp
Original file line number Diff line number Diff line change
@@ -186,16 +186,25 @@ struct ef_sequence {
m_high_bits_d0.bytes() + m_low_bits.bytes());
}

template <typename Visitor>
void visit(Visitor& visitor) const {
visit_impl(visitor, *this);
}

template <typename Visitor>
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 <typename Visitor, typename T>
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;
5 changes: 5 additions & 0 deletions include/minimizers.hpp
Original file line number Diff line number Diff line change
@@ -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 <typename Visitor>
void visit(Visitor& visitor) const {
visitor.visit(m_mphf);
}

template <typename Visitor>
void visit(Visitor& visitor) {
visitor.visit(m_mphf);
21 changes: 16 additions & 5 deletions include/skew_index.hpp
Original file line number Diff line number Diff line change
@@ -44,20 +44,31 @@ struct skew_index {
return n;
}

template <typename Visitor>
void visit(Visitor& visitor) const {
visit_impl(visitor, *this);
}

template <typename Visitor>
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;
uint16_t max_log2;
uint32_t log2_max_num_super_kmers_in_bucket;
std::vector<kmers_pthash_type> mphfs;
std::vector<pthash::compact_vector> positions;

private:
template <typename Visitor, typename T>
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
16 changes: 13 additions & 3 deletions include/weights.hpp
Original file line number Diff line number Diff line change
@@ -168,14 +168,24 @@ struct weights {
<< " [bits/kmer]\n";
}

template <typename Visitor>
void visit(Visitor& visitor) const {
visit_impl(visitor, *this);
}

template <typename Visitor>
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 <typename Visitor, typename T>
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<true> m_weight_interval_lengths;
pthash::compact_vector m_weight_dictionary;