|
@@ -40,13 +40,17 @@ static void setBits(int* data, int index, int bits, int value) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static int getArrayLength(int length, int bits) {
|
|
|
+ return roundUpDivide(length * bits, sizeof(int) * 8);
|
|
|
+}
|
|
|
+
|
|
|
BitArray::BitArray() : length(0), bits(0), data(nullptr) {
|
|
|
}
|
|
|
|
|
|
BitArray::BitArray(int length, int bits)
|
|
|
: length(length), bits(bits), data(nullptr) {
|
|
|
if(length > 0 && bits > 0) {
|
|
|
- data = new int[roundUpDivide(length * bits, sizeof(int))];
|
|
|
+ data = new int[getArrayLength(length, bits)];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -90,7 +94,7 @@ int BitArray::getInternalByteSize() const {
|
|
|
if(bits <= 0 || length <= 0) {
|
|
|
return 0;
|
|
|
}
|
|
|
- return roundUpDivide(length * bits, sizeof(int)) * sizeof(int);
|
|
|
+ return getArrayLength(length, bits) * sizeof(int);
|
|
|
}
|
|
|
|
|
|
void BitArray::fill(int value) {
|
|
@@ -100,7 +104,7 @@ void BitArray::fill(int value) {
|
|
|
}
|
|
|
|
|
|
void BitArray::resize(int newLength, int newBits) {
|
|
|
- int* newData = new int[roundUpDivide(newLength * newBits, sizeof(int))];
|
|
|
+ int* newData = new int[getArrayLength(newLength, newBits)];
|
|
|
int end = Math::min(length, newLength);
|
|
|
for(int i = 0; i < end; i++) {
|
|
|
setBits(newData, i, newBits, get(i));
|