BitArray.h 885 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef BITARRAY_H
  2. #define BITARRAY_H
  3. #include "utils/StringBuffer.h"
  4. class BitArray final {
  5. int length;
  6. int bits;
  7. int* data;
  8. public:
  9. BitArray();
  10. BitArray(int length, int bits);
  11. BitArray(const BitArray& other);
  12. BitArray(BitArray&& other);
  13. ~BitArray();
  14. BitArray& operator=(BitArray other);
  15. BitArray& set(int index, int value);
  16. int get(int index) const;
  17. int getLength() const;
  18. int getBits() const;
  19. void resize(int newLength, int newBits);
  20. void fill(int value);
  21. template<int L>
  22. void toString(StringBuffer<L>& s) const {
  23. s.append("[");
  24. for(int i = 0; i < length - 1; i++) {
  25. s.append(get(i));
  26. s.append(", ");
  27. }
  28. if(length > 0) {
  29. s.append(get(length - 1));
  30. }
  31. s.append("]");
  32. }
  33. private:
  34. void swap(BitArray& other);
  35. };
  36. #endif