diff --git a/external/essentials b/external/essentials index 6168ece..2a546e3 160000 --- a/external/essentials +++ b/external/essentials @@ -1 +1 @@ -Subproject commit 6168ece5738563533c31d578f34b430f9ee1dd38 +Subproject commit 2a546e3790ed1e2828e70254988eed73b9b56dd0 diff --git a/include/builders/internal_memory_builder_single_phf.hpp b/include/builders/internal_memory_builder_single_phf.hpp index 4f21b7d..029bbff 100644 --- a/include/builders/internal_memory_builder_single_phf.hpp +++ b/include/builders/internal_memory_builder_single_phf.hpp @@ -174,15 +174,14 @@ struct internal_memory_builder_single_phf { m_free_slots.swap(other.m_free_slots); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_seed); - visitor.visit(m_num_keys); - visitor.visit(m_num_buckets); - visitor.visit(m_table_size); - visitor.visit(m_bucketer); - visitor.visit(m_pilots); - visitor.visit(m_free_slots); + visit_impl(visitor, *this); } static uint64_t estimate_num_bytes_for_construction(uint64_t num_keys, @@ -208,6 +207,17 @@ struct internal_memory_builder_single_phf { } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_seed); + visitor.visit(t.m_num_keys); + visitor.visit(t.m_num_buckets); + visitor.visit(t.m_table_size); + visitor.visit(t.m_bucketer); + visitor.visit(t.m_pilots); + visitor.visit(t.m_free_slots); + } + uint64_t m_seed; uint64_t m_num_keys; uint64_t m_num_buckets; diff --git a/include/encoders/bit_vector.hpp b/include/encoders/bit_vector.hpp index a159e0c..7ff048b 100644 --- a/include/encoders/bit_vector.hpp +++ b/include/encoders/bit_vector.hpp @@ -295,13 +295,23 @@ struct bit_vector { uint64_t m_buf; }; + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_size); - visitor.visit(m_bits); + visit_impl(visitor, *this); } protected: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_size); + visitor.visit(t.m_bits); + } + size_t m_size; std::vector m_bits; }; diff --git a/include/encoders/compact_vector.hpp b/include/encoders/compact_vector.hpp index 7497fc0..d46ef82 100644 --- a/include/encoders/compact_vector.hpp +++ b/include/encoders/compact_vector.hpp @@ -274,15 +274,24 @@ struct compact_vector { m_bits.swap(other.m_bits); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_size); - visitor.visit(m_width); - visitor.visit(m_mask); - visitor.visit(m_bits); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_size); + visitor.visit(t.m_width); + visitor.visit(t.m_mask); + visitor.visit(t.m_bits); + } uint64_t m_size; uint64_t m_width; uint64_t m_mask; diff --git a/include/encoders/darray.hpp b/include/encoders/darray.hpp index 5b5c0ac..ef37d48 100644 --- a/include/encoders/darray.hpp +++ b/include/encoders/darray.hpp @@ -85,15 +85,25 @@ struct darray { essentials::vec_bytes(m_overflow_positions); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_positions); - visitor.visit(m_block_inventory); - visitor.visit(m_subblock_inventory); - visitor.visit(m_overflow_positions); + visit_impl(visitor, *this); } protected: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_positions); + visitor.visit(t.m_block_inventory); + visitor.visit(t.m_subblock_inventory); + visitor.visit(t.m_overflow_positions); + } + static void flush_cur_block(std::vector& cur_block_positions, std::vector& block_inventory, std::vector& subblock_inventory, diff --git a/include/encoders/ef_sequence.hpp b/include/encoders/ef_sequence.hpp index 22a5240..f0bfecc 100644 --- a/include/encoders/ef_sequence.hpp +++ b/include/encoders/ef_sequence.hpp @@ -79,14 +79,23 @@ struct ef_sequence { return 8 * (m_high_bits.bytes() + m_high_bits_d1.bytes() + m_low_bits.bytes()); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_high_bits); - visitor.visit(m_high_bits_d1); - visitor.visit(m_low_bits); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_high_bits); + visitor.visit(t.m_high_bits_d1); + visitor.visit(t.m_low_bits); + } bit_vector m_high_bits; darray1 m_high_bits_d1; compact_vector m_low_bits; diff --git a/include/encoders/encoders.hpp b/include/encoders/encoders.hpp index 2dcf571..2f08f0c 100644 --- a/include/encoders/encoders.hpp +++ b/include/encoders/encoders.hpp @@ -32,6 +32,11 @@ struct compact { return m_values.access(i); } + template + void visit(Visitor& visitor) const { + visitor.visit(m_values); + } + template void visit(Visitor& visitor) { visitor.visit(m_values); @@ -97,14 +102,23 @@ struct partitioned_compact { return m_values.get_bits(position, num_bits); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_size); - visitor.visit(m_bits_per_value); - visitor.visit(m_values); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_size); + visitor.visit(t.m_bits_per_value); + visitor.visit(t.m_values); + } uint64_t m_size; std::vector m_bits_per_value; bit_vector m_values; @@ -169,13 +183,22 @@ struct dictionary { return m_dict.access(rank); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_ranks); - visitor.visit(m_dict); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_ranks); + visitor.visit(t.m_dict); + } compact_vector m_ranks; compact_vector m_dict; }; @@ -203,6 +226,11 @@ struct elias_fano { return m_values.diff(i); } + template + void visit(Visitor& visitor) const { + visitor.visit(m_values); + } + template void visit(Visitor& visitor) { visitor.visit(m_values); @@ -270,13 +298,23 @@ struct dual { return m_back.access(i - m_front.size()); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_front); - visitor.visit(m_back); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_front); + visitor.visit(t.m_back); + } + Front m_front; Back m_back; }; diff --git a/include/partitioned_phf.hpp b/include/partitioned_phf.hpp index 69ec53c..f963d92 100644 --- a/include/partitioned_phf.hpp +++ b/include/partitioned_phf.hpp @@ -12,14 +12,25 @@ template struct partitioned_phf { private: struct partition { + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(offset); - visitor.visit(f); + visit_impl(visitor, *this); } uint64_t offset; single_phf f; + + private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.offset); + visitor.visit(t.f); + } }; public: @@ -137,16 +148,26 @@ struct partitioned_phf { return m_seed; } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_seed); - visitor.visit(m_num_keys); - visitor.visit(m_table_size); - visitor.visit(m_bucketer); - visitor.visit(m_partitions); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_seed); + visitor.visit(t.m_num_keys); + visitor.visit(t.m_table_size); + visitor.visit(t.m_bucketer); + visitor.visit(t.m_partitions); + } + uint64_t m_seed; uint64_t m_num_keys; uint64_t m_table_size; diff --git a/include/single_phf.hpp b/include/single_phf.hpp index f229c7d..8d28d50 100644 --- a/include/single_phf.hpp +++ b/include/single_phf.hpp @@ -96,18 +96,27 @@ struct single_phf { return m_seed; } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_seed); - visitor.visit(m_num_keys); - visitor.visit(m_table_size); - visitor.visit(m_M); - visitor.visit(m_bucketer); - visitor.visit(m_pilots); - visitor.visit(m_free_slots); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_seed); + visitor.visit(t.m_num_keys); + visitor.visit(t.m_table_size); + visitor.visit(t.m_M); + visitor.visit(t.m_bucketer); + visitor.visit(t.m_pilots); + visitor.visit(t.m_free_slots); + } uint64_t m_seed; uint64_t m_num_keys; uint64_t m_table_size; diff --git a/include/utils/bucketers.hpp b/include/utils/bucketers.hpp index 5260940..b98e3be 100644 --- a/include/utils/bucketers.hpp +++ b/include/utils/bucketers.hpp @@ -41,15 +41,25 @@ struct skew_bucketer { std::swap(m_M_num_sparse_buckets, other.m_M_num_sparse_buckets); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_num_dense_buckets); - visitor.visit(m_num_sparse_buckets); - visitor.visit(m_M_num_dense_buckets); - visitor.visit(m_M_num_sparse_buckets); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_num_dense_buckets); + visitor.visit(t.m_num_sparse_buckets); + visitor.visit(t.m_M_num_dense_buckets); + visitor.visit(t.m_M_num_sparse_buckets); + } + uint64_t m_num_dense_buckets, m_num_sparse_buckets; __uint128_t m_M_num_dense_buckets, m_M_num_sparse_buckets; }; @@ -74,13 +84,22 @@ struct uniform_bucketer { return 8 * (sizeof(m_num_buckets) + sizeof(m_M_num_buckets)); } + template + void visit(Visitor& visitor) const { + visit_impl(visitor, *this); + } + template void visit(Visitor& visitor) { - visitor.visit(m_num_buckets); - visitor.visit(m_M_num_buckets); + visit_impl(visitor, *this); } private: + template + static void visit_impl(Visitor& visitor, T&& t) { + visitor.visit(t.m_num_buckets); + visitor.visit(t.m_M_num_buckets); + } uint64_t m_num_buckets; __uint128_t m_M_num_buckets; };