#ifndef CORE_BIT_ARRAY_HPP
#define CORE_BIT_ARRAY_HPP

#include "core/utils/ArrayString.hpp"

namespace Core {
    class BitArray final {
        u64 lengthBits;
        u64* data;

    public:
        BitArray();
        BitArray(const BitArray& other);
        BitArray(BitArray&& other);
        ~BitArray();
        BitArray& operator=(BitArray other);

        BitArray& set(size_t index, u64 value);
        u64 get(size_t index) const;
        size_t getLength() const;
        size_t getBits() const;
        size_t getInternalByteSize() const;
        i64 select(size_t index) const;
        CError resize(size_t newLength, size_t newBits);
        void fill(u64 value);

        void toString(BufferString& s) const {
            s.append("[");
            size_t length = getLength();
            if(length > 0) {
                length--;
                for(size_t i = 0; i < length; i++) {
                    s.append(get(i)).append(", ");
                }
                s.append(get(length));
            }
            s.append("]");
        }

        void swap(BitArray& other);
    };
}

#endif