From 17d2baf7365c3499172dc5afd71171cb3a138d99 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 8 Jul 2024 18:17:15 +0200 Subject: [PATCH] add invert to bitset --- solanaceae/util/bitset.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/solanaceae/util/bitset.hpp b/solanaceae/util/bitset.hpp index 43642be..2a0c4f4 100644 --- a/solanaceae/util/bitset.hpp +++ b/solanaceae/util/bitset.hpp @@ -18,6 +18,7 @@ struct BitSet { BitSet(size_t size) { _bytes.resize((size+7)/8); } + BitSet(const std::vector& 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