BitArray.h 922 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. int getInternalByteSize() const;
  20. void resize(int newLength, int newBits);
  21. void fill(int value);
  22. template<int L>
  23. void toString(StringBuffer<L>& s) const {
  24. s.append("[");
  25. for(int i = 0; i < length - 1; i++) {
  26. s.append(get(i));
  27. s.append(", ");
  28. }
  29. if(length > 0) {
  30. s.append(get(length - 1));
  31. }
  32. s.append("]");
  33. }
  34. private:
  35. void swap(BitArray& other);
  36. };
  37. #endif