add invert to bitset
This commit is contained in:
parent
6b1bb50f16
commit
17d2baf736
@ -18,6 +18,7 @@ struct BitSet {
|
||||
BitSet(size_t size) {
|
||||
_bytes.resize((size+7)/8);
|
||||
}
|
||||
BitSet(const std::vector<uint8_t>& bytes) : _bytes(bytes) {}
|
||||
|
||||
BitSet& operator=(const BitSet&) = default;
|
||||
BitSet& operator=(BitSet&&) = default;
|
||||
@ -75,6 +76,20 @@ struct BitSet {
|
||||
return _bytes.size();
|
||||
}
|
||||
|
||||
BitSet& invert(void) {
|
||||
for (auto& c : _bytes) {
|
||||
c = ~c;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] BitSet invert(void) const {
|
||||
BitSet copy = *this;
|
||||
copy.invert();
|
||||
return copy;
|
||||
}
|
||||
|
||||
BitSet& merge(const BitSet& other) {
|
||||
if (other.size_bytes() > size_bytes()) {
|
||||
_bytes.resize(other.size_bytes());
|
||||
@ -87,6 +102,12 @@ struct BitSet {
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] BitSet merge(const BitSet& other) const {
|
||||
BitSet copy = *this;
|
||||
copy.merge(other);
|
||||
return copy;
|
||||
}
|
||||
|
||||
// start is the first bit in other relative to self
|
||||
BitSet& merge(const BitSet& other, size_t start) {
|
||||
// TODO: efficent implementation
|
||||
|
Loading…
Reference in New Issue
Block a user