BitVecLen
- Macro
- August 22, 2025
Table of Contents
BitVecLen
BitVecLen
Description
Get number of bits currently in bitvector.
Parameters
Name | Direction | Description |
---|---|---|
bv | in | Bitvector to get length of |
Usage example (from documentation)
u64 num_bits = BitVecLen(&flags);
Usage example (Cross-references)
- In
Access.h:100
:
/// TAGS: BitVec, Empty, Check
///
#define BitVecEmpty(bv) (BitVecLen(bv) == 0)
///
// Initially empty
bool result = (BitVecLen(&bv) == 0);
// Push some bits
BitVecPush(&bv, true);
result = result && (BitVecLen(&bv) == 3);
result = result && (BitVecCapacity(&bv) >= 3);
// Reserve more space
BitVecReserve(&bv, 100);
result = result && (BitVecLen(&bv) == 3);
result = result && (BitVecCapacity(&bv) >= 100);
// Test length and capacity macros if they exist
result = result && (BitVecLen(&bv) == 2);
result = result && (BitVecCapacity(&bv) >= 2);
// Check result should be: 101110
result = result && (BitVecLen(&source) == 6);
result = result && (BitVecGet(&source, 0) == true);
result = result && (BitVecGet(&source, 1) == false);
// Check final length
result = result && (BitVecLen(&source) == 6); // 3 * 2 = 6
BitVecDeinit(&source);
// Check result should be: 101110
result = result && (BitVecLen(&source) == 6);
result = result && (BitVecGet(&source, 0) == true);
result = result && (BitVecGet(&source, 1) == false);
// Check final length
result = result && (BitVecLen(&source) == 6); // 3 * 2 = 6
BitVecDeinit(&source);
// Initially should be empty
bool result = (BitVecLen(&bv) == 0) && (BitVecCapacity(&bv) == 0);
// Add some bits
BitVecPush(&bv, true);
result = result && (BitVecLen(&bv) == 3);
result = result && (BitVecCapacity(&bv) >= 3);
BitVecClear(&bv);
result = result && BitVecEmpty(&bv);
result = result && (BitVecLen(&bv) == 0);
// Clean up
if (cycle > 0) {
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecLen(&bv) == (size)(cycle + 1));
}
// Test all macros on empty bitvector
result = result && (BitVecLen(&bv) == 0);
result = result && (BitVecCapacity(&bv) == 0);
result = result && BitVecEmpty(&bv);
}
result = result && (BitVecLen(&bv) == 65);
result = result && (BitVecCapacity(&bv) >= 65);
result = result && !BitVecEmpty(&bv);
}
result = result && (BitVecLen(&bv) == 64);
result = result && (BitVecByteSize(&bv) >= 8); // At least 8 bytes for 64 bits