diff --git a/include/base_set.h b/include/base_set.h index b4480ef2c2..c8407ee12c 100644 --- a/include/base_set.h +++ b/include/base_set.h @@ -186,21 +186,75 @@ public: // Compound assignment AND operator BASE_SET& operator&=(const BASE_SET& other) { - sul::dynamic_bitset<uint64_t>::operator&=(other); + size_t my_size = size(); + size_t other_size = other.size(); + + if( my_size == other_size ) + { + sul::dynamic_bitset<uint64_t>::operator&=(other); + } + else if( my_size < other_size ) + { + sul::dynamic_bitset<uint64_t>::resize( other_size ); + sul::dynamic_bitset<uint64_t>::operator&=( other ); + } + else + { + BASE_SET tmp( other ); + tmp.resize( my_size ); + sul::dynamic_bitset<uint64_t>::operator&=( tmp ); + } + return *this; } // Compound assignment OR operator BASE_SET& operator|=(const BASE_SET& other) { - sul::dynamic_bitset<uint64_t>::operator|=(other); + size_t my_size = size(); + size_t other_size = other.size(); + + if( my_size == other_size ) + { + sul::dynamic_bitset<uint64_t>::operator|=(other); + } + else if( my_size < other_size ) + { + sul::dynamic_bitset<uint64_t>::resize( other_size ); + sul::dynamic_bitset<uint64_t>::operator|=( other ); + } + else + { + BASE_SET tmp( other ); + tmp.resize( my_size ); + sul::dynamic_bitset<uint64_t>::operator|=( tmp ); + } + return *this; } // Compound assignment XOR operator BASE_SET& operator^=(const BASE_SET& other) { - sul::dynamic_bitset<uint64_t>::operator^=(other); + size_t my_size = size(); + size_t other_size = other.size(); + + if( my_size == other_size ) + { + sul::dynamic_bitset<uint64_t>::operator^=(other); + } + else if( my_size < other_size ) + { + sul::dynamic_bitset<uint64_t>::resize( other_size ); + sul::dynamic_bitset<uint64_t>::operator^=( other ); + } + else + { + BASE_SET tmp( other ); + tmp.resize( my_size ); + sul::dynamic_bitset<uint64_t>::operator^=( tmp ); + } + return *this; }