summaryrefslogtreecommitdiff
path: root/include/util/bitset.hpp
diff options
context:
space:
mode:
authorhovertank3d <[email protected]>2025-11-14 20:05:59 +0100
committerhovertank3d <[email protected]>2025-11-15 14:03:07 +0100
commitfa318825ef0404816728f733484caa1bc23afa53 (patch)
tree154d51e23f907102cbb8367b8cdc4d3bb4153dc1 /include/util/bitset.hpp
parent6c1a6c62bb13d09a0beb51ebb5cd5e4a69d9fe5a (diff)
downloadogurec-fa318825ef0404816728f733484caa1bc23afa53.tar.gz
ogurec-fa318825ef0404816728f733484caa1bc23afa53.zip
george droid
Diffstat (limited to 'include/util/bitset.hpp')
-rw-r--r--include/util/bitset.hpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/include/util/bitset.hpp b/include/util/bitset.hpp
index de5bd49..cd1dbd0 100644
--- a/include/util/bitset.hpp
+++ b/include/util/bitset.hpp
@@ -3,6 +3,7 @@
#include <array>
#include <cassert>
#include <cstdint>
+#include <vector>
constexpr int bits_ceil(int bits)
{
@@ -50,4 +51,48 @@ public:
assert(i < flags);
return bit_ref(*this, i / 8, (1 << (i % 8)));
}
+};
+
+// FIXME: ??
+template <>
+struct bitset<0> : std::vector<std::uint8_t> {
+ using container_type = std::vector<std::uint8_t>;
+
+private:
+ struct bit_ref {
+ bitset<0>& a;
+ int referenced_byte;
+ uint8_t referenced_bit_mask;
+
+ bool operator=(bool b)
+ {
+ if (b)
+ a.at(referenced_byte) |= referenced_bit_mask;
+ else
+ a.at(referenced_byte) &= ~referenced_bit_mask;
+ return b;
+ }
+
+ constexpr operator bool() const
+ {
+ return (a.at(referenced_byte) & referenced_bit_mask) > 0;
+ }
+ };
+
+public:
+ template <class T>
+ constexpr bool operator[](T idx) const
+ {
+ unsigned int i = (unsigned int)(idx);
+ assert(i < container_type::size());
+ return (container_type::at(i / 8) & (1 << (i % 8))) > 0;
+ }
+
+ template <class T>
+ bit_ref operator[](T idx)
+ {
+ unsigned int i = (unsigned int)(idx);
+ assert(i < container_type::size());
+ return bit_ref(*this, i / 8, (1 << (i % 8)));
+ }
}; \ No newline at end of file