BitSet BitSet::operator&=(const BitSet& that) { int maxLength = std::max(this->length(), that.length()); for (int i = 0; i < maxLength; ++i) { if (i >= this->length() || i >= that.length()) { this->put(false, i); } else { this->put((*this)[i] && that[i], i); } } return *this; }
BitSet BitSet::operator&(const BitSet& that) { BitSet bs; int maxLength = std::max(this->length(), that.length()); for (int i = 0; i < maxLength; ++i) { if (i >= this->length() || i >= that.length()) { bs.add(false); } else { bs.add((*this)[i] && that[i]); } } return bs; }
BitSet BitSet::operator|=(const BitSet& that) { int maxLength = std::max(this->length(), that.length()); for (int i = 0; i < maxLength; ++i) { if (i < this->length() && i >= that.length()) { this->put((*this)[i], i); } else if (i >= this->length() && i < that.length()) { this->put(that[i], i); } else { this->put((*this)[i] || that[i], i); } } return *this; }
BitSet BitSet::operator+(const BitSet& that) { BitSet result(*this); for (int i = 0; i < that.length(); ++i) { result.add(that.get(i)); } return result; }