From 5740421d546f9725086d27db6332eae8833a6330 Mon Sep 17 00:00:00 2001 From: drfrag666 Date: Mon, 12 Nov 2018 21:12:57 +0100 Subject: [PATCH] - Even more TArray changes. (patches by Graf) --- src/tarray.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/tarray.h b/src/tarray.h index 63eeb4eed..1966ed7d3 100644 --- a/src/tarray.h +++ b/src/tarray.h @@ -560,6 +560,10 @@ public: { return Array[index]; } + T &At(size_t index) const + { + return Array[index]; + } unsigned int Size() const { return Count; @@ -1221,3 +1225,73 @@ protected: hash_t Position; }; + +class BitArray +{ + TArray bytes; + unsigned size; + +public: + void Resize(unsigned elem) + { + bytes.Resize((elem + 7) / 8); + size = elem; + } + + BitArray() : size(0) + { + } + + BitArray(const BitArray & arr) + { + bytes = arr.bytes; + size = arr.size; + } + + BitArray &operator=(const BitArray & arr) + { + bytes = arr.bytes; + size = arr.size; + return *this; + } + + BitArray(BitArray && arr) + { + bytes = std::move(arr.bytes); + size = arr.size; + arr.size = 0; + } + + BitArray &operator=(BitArray && arr) + { + bytes = std::move(arr.bytes); + size = arr.size; + arr.size = 0; + return *this; + } + + bool operator[](size_t index) const + { + return !!(bytes[index >> 3] & (1 << (index & 7))); + } + + void Set(size_t index) + { + bytes[index >> 3] |= (1 << (index & 7)); + } + + void Clear(size_t index) + { + bytes[index >> 3] &= ~(1 << (index & 7)); + } + + unsigned Size() const + { + return size; + } + + void Zero() + { + memset(&bytes[0], 0, bytes.Size()); + } +};