77 inline quint8
getBit(
int index)
const {
78 return (content[index/8] >> (7-index%8)) & 0x01;
89 inline void setBit(
int index, quint8 bit) {
90 quint32 byteIndex = index/8;
92 content[byteIndex] = content[byteIndex] | (0b00000001 << (7-index%8));
94 content[byteIndex] = content[byteIndex] & ~(0b00000001 << (7-index%8));
170 if (_size+32 > content.size()*8)
171 content.resize(2*content.size()+1000);
173 quint32 value = mbv.
value;
174 for(
int i=0; i<mbv.
numBits; i++) {
175 bool bit = value & 0x01;
193 operator QByteArray();
199 operator QString()
const;
212 static inline quint8
getBit(
const quint8 *ptr,
int index) {
213 return (ptr[index/8] >> (7-index%8)) & 0x01;
227 static inline void setBit(quint8 *ptr,
int index, quint8 bit) {
228 quint32 byteIndex = index/8;
230 ptr[byteIndex] = ptr[byteIndex] | (0b00000001 << (7-index%8));
232 ptr[byteIndex] = ptr[byteIndex] & ~(0b00000001 << (7-index%8));
251 static inline void fill(quint8 *ptr,
int startIndex,
int numBits, quint8 bit) {
252 quint32 endIndex = startIndex+numBits;
253 quint32 index=startIndex;
254 while(index < endIndex) {
257 uintptr_t currentBytePtr = (uintptr_t)(ptr+index/8);
259 if ((currentBytePtr%8 == 0) && (index+64<endIndex)) {
260 *((quint64 *)currentBytePtr) = (bit == 0) ? 0x0000000000000000 : 0xFFFFFFFFFFFFFFFF;
265 if ((currentBytePtr%4 == 0) && (index+32<endIndex)) {
266 *((quint32 *)currentBytePtr) = (bit == 0) ? 0x00000000 : 0xFFFFFFFF;
271 if ((currentBytePtr%2 == 0) && (index+16<endIndex)) {
273 *((quint16 *)currentBytePtr) = (bit == 0) ? 0x0000 : 0xFFFF;
278 if (index+8<endIndex) {
279 ptr[index/8] = (bit == 0) ? 0x00 : 0xFF;
304 static inline int findEndOfRun(
const quint8 *ptr,
int startIndex,
int endIndex, quint8 runValue) {
305 int index=startIndex;
307 while(index < endIndex) {
310 uintptr_t currentBytePtr = (uintptr_t)(ptr+index/8);
313 if ((currentBytePtr%8 == 0) && (endIndex-index >= 64)) {
315 if ( *((quint64 *)currentBytePtr) == 0) {
320 if ( *((quint64 *)currentBytePtr) == 0xFFFFFFFFFFFFFFFF) {
328 if ((currentBytePtr%4 == 0) && (endIndex-index >= 32)) {
330 if ( *((quint32 *)currentBytePtr) == 0) {
335 if ( *((quint32 *)currentBytePtr) == 0xFFFFFFFF) {
343 if ((currentBytePtr%2 == 0) && (endIndex-index >= 16)) {
345 if ( *((quint16 *)currentBytePtr) == 0) {
350 if ( *((quint16 *)currentBytePtr) == 0xFFFF) {
358 if (endIndex-index >= 8) {
360 if (ptr[index/8] == 0) {
365 if (ptr[index/8] == 0xFF) {
Simple array of bits, useful for static data.
quint8 numBits
Number of bits stored, must be smaller than or equal to 32.
quint32 value
Array of bits, there the least significant bit is the last of the bits stored.
quint8 getBit(int index) const
Returns the bit at position index.
The bitVector class provides an array of bits, similar to QBitArray.
void resize(int newSize)
Sets the size of the bitVector array to newSize bits.
bitVector(int numBits)
Constructs an array of size bits.
static quint8 getBit(const quint8 *ptr, int index)
Convenience method for read access to a bit in a C-array of bytes.
int size() const
Size of the bitVector in bits.
static void setBit(quint8 *ptr, int index, quint8 bit)
Convenience method for write access to a bit in a C-array of bytes.
bool startsWith(const miniBitVector &mbv, int index=0) const
Check if the content of the given miniBitVector is found at a given position.
static int findEndOfRun(const quint8 *ptr, int startIndex, int endIndex, quint8 runValue)
Searches for end of a run of consecutive bits with same value.
quint8 getBit(int index) const
Returns the bit at position index.
bitVector(QByteArray data)
Constructs a bitVector from a QByteArray.
void append(const miniBitVector &mbv)
Appends a miniBitVector to the end of the bitVector.
bitVector()
Constructs an empty bit array.
static void fill(quint8 *ptr, int startIndex, int numBits, quint8 bit)
Convenience method for write access to a continuous block of bits in a C-array of bytes.
void setBit(int index, quint8 bit)
Sets the bit at position index.