#ifndef BITARRAY_H
#define BITARRAY_H

#include "utils/StringBuffer.h"

class BitArray final {
    int length;
    int bits;
    int* data;

public:
    BitArray(int length, int bits);
    BitArray(const BitArray& other);
    BitArray(BitArray&& other);
    ~BitArray();
    BitArray& operator=(BitArray other);

    BitArray& set(int index, int value);
    int get(int index) const;

    int getLength() const;
    int getBits() const;

    void resize(int newBits);

    void fill(int value);

    template<int L>
    void toString(StringBuffer<L>& s) const {
        s.append("[");
        for(int i = 0; i < length - 1; i++) {
            s.append(get(i));
            s.append(", ");
        }
        if(length > 0) {
            s.append(get(length - 1));
        }
        s.append("]");
    }

private:
    void swap(BitArray& other);
};

#endif