diff --git a/include/rabitqlib/core/query.hpp b/include/rabitqlib/core/query.hpp index e053dc47..531e4846 100644 --- a/include/rabitqlib/core/query.hpp +++ b/include/rabitqlib/core/query.hpp @@ -30,6 +30,26 @@ class SplitSingleQuery { public: static constexpr size_t kNumBits = 4; + + SplitSingleQuery(const SplitSingleQuery&) = default; + SplitSingleQuery(SplitSingleQuery&&) noexcept = default; + SplitSingleQuery& operator=(SplitSingleQuery&&) noexcept = default; + + SplitSingleQuery& operator=(const SplitSingleQuery& other) { + // Copy owned codes before changing their borrowed query and corrections. + query_bin_ = other.query_bin_; + rotated_query_ = other.rotated_query_; + G_add_ = other.G_add_; + G_k1xSumq_ = other.G_k1xSumq_; + G_kbaseSumq_ = other.G_kbaseSumq_; + G_kbxSumq_ = other.G_kbxSumq_; + G_error_ = other.G_error_; + delta_ = other.delta_; + vl_ = other.vl_; + metric_type_ = other.metric_type_; + return *this; + } + explicit SplitSingleQuery( const T* rotated_query, size_t padded_dim, diff --git a/include/rabitqlib/core/rotator.hpp b/include/rabitqlib/core/rotator.hpp index ee0f9c7c..5abaa5f2 100644 --- a/include/rabitqlib/core/rotator.hpp +++ b/include/rabitqlib/core/rotator.hpp @@ -214,7 +214,17 @@ class FhtKacRotator : public Rotator { size_t dump_bytes() const override { return sizeof(uint8_t) * flip_.size(); } - FhtKacRotator& operator=(const FhtKacRotator&) = default; + FhtKacRotator(const FhtKacRotator&) = default; + + FhtKacRotator& operator=(const FhtKacRotator& other) { + // Preserve the old dimensions if copying the sign storage fails. + flip_ = other.flip_; + this->dim_ = other.dim_; + this->padded_dim_ = other.padded_dim_; + trunc_dim_ = other.trunc_dim_; + fac_ = other.fac_; + return *this; + } static void kacs_walk(float* data, size_t len) { simd::kacs_walk(data, len); } diff --git a/include/rabitqlib/index/detail/visited_set_hash.hpp b/include/rabitqlib/index/detail/visited_set_hash.hpp index 9baa0f50..a79478f1 100644 --- a/include/rabitqlib/index/detail/visited_set_hash.hpp +++ b/include/rabitqlib/index/detail/visited_set_hash.hpp @@ -57,7 +57,13 @@ class HashBasedVisitedSet { ~HashBasedVisitedSet() = default; HashBasedVisitedSet(const HashBasedVisitedSet&) = default; - HashBasedVisitedSet& operator=(const HashBasedVisitedSet&) = default; + HashBasedVisitedSet& operator=(const HashBasedVisitedSet& other) { + if (this != &other) { + // Both containers may allocate; publish only a complete replacement. + *this = HashBasedVisitedSet(other); + } + return *this; + } HashBasedVisitedSet(HashBasedVisitedSet&&) noexcept = default; HashBasedVisitedSet& operator=(HashBasedVisitedSet&&) noexcept = default;