BitVecLen
Description
Number of bits currently held by the bitvector.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Access.h:115:
/// TAGS: BitVec, Empty, Check
///
#define BitVecEmpty(bv) (BitVecLen(bv) == 0)
///
- In
Io.c:3052:
if (fmt_info->flags & FMT_FLAG_HEX) {
if (BitVecLen(bv) == 0) {
// Render "0x0" / "0o0" placeholders for the zero-length
// edge case so the prefix is visible even with no bits.
- In
Io.c:3069:
}
} else if (fmt_info->flags & FMT_FLAG_OCTAL) {
if (BitVecLen(bv) == 0) {
if (!StrPushBackMany(o, "0o0")) {
return false;- In
Io.c:3083:
// No flag -> render the raw 0/1 bit string (the BitVec's
// native textual form).
if (BitVecLen(bv) == 0) {
// A zero-length BitVec renders empty; padding handles any
// requested width below.
- In
Int.c:66:
ValidateInt(value);
u64 len = BitVecLen(INT_BITS(value));
if (len == 0) {- In
Int.c:249:
static bool int_is_odd(const Int *value) {
ValidateInt(value);
return BitVecLen(INT_BITS(value)) > 0 && BitVecGet(INT_BITS(value), 0);
}- In
Int.c:429:
ValidateInt(value);
for (u64 i = 0; i < BitVecLen(INT_BITS(value)); i++) {
if (BitVecGet(INT_BITS(value), i)) {
return i;- In
Int.c:580:
u64 bit_idx = i * 8 + bit;
if (bit_idx < BitVecLen(INT_BITS(value)) && BitVecGet(INT_BITS(value), bit_idx)) {
byte |= (u8)(1u << bit);
}- In
Int.c:634:
u64 bit_idx = i * 8 + bit;
if (bit_idx < BitVecLen(INT_BITS(value)) && BitVecGet(INT_BITS(value), bit_idx)) {
byte |= (u8)(1u << bit);
}- In
Memory.c:53:
// Check that capacity is larger than length
u64 initial_capacity = BitVecCapacity(&bv);
bool result = (initial_capacity >= 100) && (BitVecLen(&bv) == 3);
// Shrink to fit
- In
Memory.c:60:
// Check that capacity is now closer to length
result = result && (BitVecCapacity(&bv) < initial_capacity);
result = result && (BitVecCapacity(&bv) >= BitVecLen(&bv));
// Check that data is still intact
- In
Memory.c:63:
// Check that data is still intact
result = result && (BitVecLen(&bv) == 3);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);- In
Memory.c:91:
// Check that capacity was set correctly
bool result = (BitVecCapacity(&bv) >= 50) && (BitVecLen(&bv) == 2);
// Check that data is still intact
- In
Memory.c:101:
// Capacity should still accommodate at least the current length
result = result && (BitVecCapacity(&bv) >= BitVecLen(&bv));
result = result && (BitVecLen(&bv) == 2);- In
Memory.c:102:
// Capacity should still accommodate at least the current length
result = result && (BitVecCapacity(&bv) >= BitVecLen(&bv));
result = result && (BitVecLen(&bv) == 2);
// Data should still be intact
- In
Memory.c:125:
bool result = (BitVecCapacity(&bv) == 64);
result = result && (BitVecData(&bv) != NULL);
result = result && (BitVecLen(&bv) == 0);
BitVecDeinit(&bv);- In
Memory.c:165:
// Store original states
u64 bv1_orig_length = BitVecLen(&bv1);
u64 bv2_orig_length = BitVecLen(&bv2);- In
Memory.c:166:
// Store original states
u64 bv1_orig_length = BitVecLen(&bv1);
u64 bv2_orig_length = BitVecLen(&bv2);
// Swap the bitvectors
- In
Memory.c:172:
// Check that they swapped
bool result = (BitVecLen(&bv1) == bv2_orig_length) && (BitVecLen(&bv2) == bv1_orig_length);
// Check bv1 (should now have bv2's original content)
- In
Memory.c:175:
// Check bv1 (should now have bv2's original content)
result = result && (BitVecLen(&bv1) == 2);
result = result && (BitVecGet(&bv1, 0) == false);
result = result && (BitVecGet(&bv1, 1) == false);- In
Memory.c:180:
// Check bv2 (should now have bv1's original content)
result = result && (BitVecLen(&bv2) == 3);
result = result && (BitVecGet(&bv2, 0) == true);
result = result && (BitVecGet(&bv2, 1) == false);- In
Memory.c:212:
// Check that clone has same content as original
bool result = (BitVecLen(&clone) == BitVecLen(&original));
for (u64 i = 0; i < BitVecLen(&original); i++) {- In
Memory.c:214:
bool result = (BitVecLen(&clone) == BitVecLen(&original));
for (u64 i = 0; i < BitVecLen(&original); i++) {
result = result && (BitVecGet(&clone, i) == BitVecGet(&original, i));
}- In
Memory.c:222:
// Clone should remain unchanged
result = result && (BitVecLen(&clone) == 4) && (BitVecLen(&original) == 5);
result = result && (BitVecGet(&clone, 0) == true);
result = result && (BitVecGet(&clone, 1) == false);- In
Memory.c:264:
// Clone should share the same Allocator* and therefore see identical
// configuration fields on the base allocator.
bool result = BitVecLen(&clone) == BitVecLen(&original) && BitVecCapacity(&clone) >= BitVecLen(&original) &&
BitVecAllocator(&clone) == BitVecAllocator(&original) &&
BitVecAllocator(&clone)->allocate == BitVecAllocator(&original)->allocate &&- In
Memory.c:290:
// Test shrink on empty bitvec
BitVecShrinkToFit(&bv);
result = result && (BitVecLen(&bv) == 0) && (BitVecCapacity(&bv) >= 0);
// Test shrink on single element
- In
Memory.c:295:
BitVecPush(&bv, true);
BitVecShrinkToFit(&bv);
result = result && (BitVecLen(&bv) == 1) && (BitVecCapacity(&bv) >= 1);
result = result && (BitVecGet(&bv, 0) == true);- In
Memory.c:301:
BitVecShrinkToFit(&bv);
BitVecShrinkToFit(&bv);
result = result && (BitVecLen(&bv) == 1);
// Test shrink after reserve and clear
- In
Memory.c:307:
BitVecClear(&bv);
BitVecShrinkToFit(&bv);
result = result && (BitVecLen(&bv) == 0);
BitVecDeinit(&bv);- In
Memory.c:324:
// Test set capacity on empty bitvec
BitVecReserve(&bv, 100);
result = result && (BitVecCapacity(&bv) >= 100) && (BitVecLen(&bv) == 0);
// BitVecReserve is grow-only; use BitVecClear to drop length to 0.
- In
Memory.c:328:
// BitVecReserve is grow-only; use BitVecClear to drop length to 0.
BitVecClear(&bv);
result = result && (BitVecLen(&bv) == 0);
for (int i = 0; i < 10; i++) {- In
Memory.c:333:
BitVecPush(&bv, i % 2 == 0);
}
u64 original_length = BitVecLen(&bv);
result = result && (BitVecLen(&bv) == original_length);- In
Memory.c:335:
u64 original_length = BitVecLen(&bv);
result = result && (BitVecLen(&bv) == original_length);
for (u64 i = 0; i < BitVecLen(&bv); i++) {
result = result && (BitVecGet(&bv, i) == (i % 2 == 0));- In
Memory.c:336:
result = result && (BitVecLen(&bv) == original_length);
for (u64 i = 0; i < BitVecLen(&bv); i++) {
result = result && (BitVecGet(&bv, i) == (i % 2 == 0));
}- In
Memory.c:360:
// Test swap with both empty
BitVecSwap(&bv1, &bv2);
result = result && (BitVecLen(&bv1) == 0) && (BitVecLen(&bv2) == 0);
// Test swap with one empty, one non-empty
- In
Memory.c:367:
BitVecSwap(&bv1, &bv2);
result = result && (BitVecLen(&bv1) == 0);
result = result && (BitVecLen(&bv2) == 2);
result = result && (BitVecGet(&bv2, 0) == true);- In
Memory.c:368:
result = result && (BitVecLen(&bv1) == 0);
result = result && (BitVecLen(&bv2) == 2);
result = result && (BitVecGet(&bv2, 0) == true);
result = result && (BitVecGet(&bv2, 1) == false);- In
Memory.c:379:
BitVecSwap(&bv1, &bv2);
result = result && (BitVecLen(&bv1) == 2) && (BitVecLen(&bv2) == 1000);
result = result && (BitVecGet(&bv2, 0) == true); // 0 % 3 == 0
result = result && (BitVecGet(&bv2, 999) == (999 % 3 == 0));- In
Memory.c:385:
// Test swapping with itself (should be safe)
BitVecSwap(&bv1, &bv1);
result = result && (BitVecLen(&bv1) == 2);
BitVecDeinit(&bv1);- In
Memory.c:403:
// Test clone empty bitvec
BitVec clone1 = BitVecClone(&bv);
result = result && (BitVecLen(&clone1) == 0);
BitVecDeinit(&clone1);- In
Memory.c:409:
BitVecPush(&bv, true);
BitVec clone2 = BitVecClone(&bv);
result = result && (BitVecLen(&clone2) == 1);
result = result && (BitVecGet(&clone2, 0) == true);
BitVecDeinit(&clone2);- In
Memory.c:420:
BitVec clone3 = BitVecClone(&bv);
result = result && (BitVecLen(&clone3) == 1000);
// Verify all bits match
- In
Memory.c:462:
// Verify data integrity
result = result && (BitVecLen(&clone) == cycle * 10);
if (cycle > 0) {
result = result && (BitVecGet(&clone, 0) == true); // 0 % 2 == 0
- In
Memory.c:539:
BitVecResize(&bv, 8);
bool result = (BitVecLen(&bv) == 8);
result = result && (BitVecGet(&bv, 5) == false);
result = result && (BitVecGet(&bv, 6) == false);- In
Memory.c:563:
bool result = (BitVecReserve(&bv, 0) == true);
result = result && (BitVecLen(&bv) == 0);
BitVecDeinit(&bv);- In
Memory.c:614:
BitVecShrinkToFit(&bv);
bool result = (BitVecLen(&bv) == 400);
// Every bit, including the high bits in the last byte, must survive.
- In
Memory.c:679:
// Swap marks both dirty; the next access on `small` runs the
// structural validator. Real code passes; the mutant aborts.
bool result = (BitVecLen(&small) == 400);
result = result && (BitVecGet(&small, 399) == (399 % 2 == 0));
result = result && (BitVecGet(&small, 0) == true);- In
Init.c:32:
// Check initial state
bool result = (BitVecLen(&bv) == 0);
result = result && (BitVecCapacity(&bv) == 0);
result = result && (BitVecData(&bv) == NULL);- In
Init.c:59:
// Check that data was allocated
bool result = (BitVecLen(&bv) == 3) && (BitVecData(&bv) != NULL);
// Deinitialize
- In
Init.c:67:
// Note: We can't easily test that memory was freed without causing issues,
// but we can check that the structure is reset to safe values
result = result && (BitVecLen(&bv) == 0);
result = result && (BitVecCapacity(&bv) == 0);
result = result && (BitVecData(&bv) == NULL);- In
Init.c:90:
// Check that capacity was increased
bool result = (BitVecCapacity(&bv) >= 50);
result = result && (BitVecLen(&bv) == 0); // Length should still be 0
result = result && (BitVecData(&bv) != NULL); // Memory should be allocated
- In
Init.c:98:
}
result = result && (BitVecLen(&bv) == 10);
result = result && (BitVecCapacity(&bv) >= 50); // Should still have the reserved capacity
- In
Init.c:129:
// Check initial state
bool result = (BitVecLen(&bv) == 4) && (BitVecData(&bv) != NULL);
u64 original_capacity = BitVecCapacity(&bv);- In
Init.c:136:
// Check that length is 0 but capacity and memory allocation remain
result = result && (BitVecLen(&bv) == 0);
result = result && (BitVecCapacity(&bv) == original_capacity);
result = result && (BitVecData(&bv) != NULL); // Memory should still be allocated
- In
Init.c:142:
// Test that we can still add data after clearing
BitVecPush(&bv, true);
result = result && (BitVecLen(&bv) == 1);
result = result && (BitVecGet(&bv, 0) == true);- In
Init.c:170:
// Check that length was increased and new bits have the default value
bool result = (BitVecLen(&bv) == 6);
result = result && (BitVecGet(&bv, 0) == true); // Original data
result = result && (BitVecGet(&bv, 1) == false); // Original data
- In
Init.c:182:
// Check that length was decreased and data was truncated
result = result && (BitVecLen(&bv) == 2);
result = result && (BitVecGet(&bv, 0) == true); // Original data preserved
result = result && (BitVecGet(&bv, 1) == false); // Original data preserved
- In
Init.c:188:
// Test resizing to same size (should be no-op)
BitVecResize(&bv, 2);
result = result && (BitVecLen(&bv) == 2);
// Clean up
- In
Init.c:209:
BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
bool result = (BitVecLen(&bv1) == 0) && (BitVecLen(&bv2) == 0) && (BitVecLen(&bv3) == 0);
result = result && (BitVecData(&bv1) == NULL) && (BitVecData(&bv2) == NULL) && (BitVecData(&bv3) == NULL);- In
Init.c:265:
BitVecPush(&bv, false);
BitVecResize(&bv, 0);
result = result && (BitVecLen(&bv) == 0);
// Test reu64 from 0 to non-zero
- In
Init.c:269:
// Test reu64 from 0 to non-zero
BitVecResize(&bv, 5);
result = result && (BitVecLen(&bv) == 5);
// New bits should be false
for (u64 i = 0; i < 5; i++) {- In
Init.c:277:
// Test reu64 to same size
BitVecResize(&bv, 5);
result = result && (BitVecLen(&bv) == 5);
// Test large resize
- In
Init.c:281:
// Test large resize
BitVecResize(&bv, 1000);
result = result && (BitVecLen(&bv) == 1000);
// Test shrinking from large size
- In
Init.c:285:
// Test shrinking from large size
BitVecResize(&bv, 10);
result = result && (BitVecLen(&bv) == 10);
BitVecDeinit(&bv);- In
Init.c:302:
// Test clear on empty bitvec
BitVecClear(&bv);
result = result && (BitVecLen(&bv) == 0);
// Test clear after single bit
- In
Init.c:307:
BitVecPush(&bv, true);
BitVecClear(&bv);
result = result && (BitVecLen(&bv) == 0);
// Test multiple clears
- In
Init.c:312:
BitVecClear(&bv);
BitVecClear(&bv);
result = result && (BitVecLen(&bv) == 0);
// Test clear after large data
- In
Init.c:319:
}
BitVecClear(&bv);
result = result && (BitVecLen(&bv) == 0);
BitVecDeinit(&bv);- In
Init.c:342:
}
result = result && (BitVecLen(&bv) == (size)(cycle % 10));
BitVecDeinit(&bv);
}- In
Insert.c:43:
// Check length
bool result = (BitVecLen(&bv) == 5);
// Check each bit
- In
Insert.c:72:
// Check first bit
bool result = (BitVecLen(&bv) == 1 && BitVecGet(&bv, 0) == true);
// Insert at the end
- In
Insert.c:78:
// Check bits
result = result && (BitVecLen(&bv) == 2);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);- In
Insert.c:86:
// Check all bits
result = result && (BitVecLen(&bv) == 3);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == true);- In
Insert.c:115:
// Check result: false, true, true, true, false
bool result = (BitVecLen(&bv) == 5);
result = result && (BitVecGet(&bv, 0) == false);
result = result && (BitVecGet(&bv, 1) == true);- In
Insert.c:152:
// Check result: true, true, true, true, false
bool result = (BitVecLen(&bv) == 5);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == true);- In
Insert.c:186:
// Check result: false, true, false, true, true, false
// Pattern 1011 gets inserted as individual bits
bool result = (BitVecLen(&bv) == 6);
result = result && (BitVecGet(&bv, 0) == false); // original
result = result && (BitVecGet(&bv, 1) == true); // bit 0 of pattern (LSB)
- In
Insert.c:202:
// Check result: true, false, true, true (3 bits: 101)
result = result && (BitVecLen(&bv2) == 4);
result = result && (BitVecGet(&bv2, 0) == true); // bit 0 of pattern (LSB)
result = result && (BitVecGet(&bv2, 1) == false); // bit 1 of pattern
- In
Insert.c:228:
// Test inserting 0 bits (should be no-op)
BitVecInsertRange(&bv, 0, 0, true);
result = result && (BitVecLen(&bv) == 0);
// Test inserting at end
- In
Insert.c:233:
BitVecPush(&bv, true);
BitVecInsertRange(&bv, 1, 2, false);
result = result && (BitVecLen(&bv) == 3);
result = result && (BitVecGet(&bv, 1) == false);
result = result && (BitVecGet(&bv, 2) == false);- In
Insert.c:240:
BitVecClear(&bv);
BitVecInsertRange(&bv, 0, 1000, true);
result = result && (BitVecLen(&bv) == 1000);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 999) == true);- In
Insert.c:261:
// Test inserting empty bitvec
BitVecInsertMultiple(&bv, 0, &empty);
result = result && (BitVecLen(&bv) == 0);
// Test inserting single bit bitvec
- In
Insert.c:266:
BitVecPush(&source, true);
BitVecInsertMultiple(&bv, 0, &source);
result = result && (BitVecLen(&bv) == 1) && (BitVecGet(&bv, 0) == true);
// Test inserting large bitvec
- In
Insert.c:274:
}
BitVecInsertMultiple(&bv, 1, &source);
result = result && (BitVecLen(&bv) == 501);
result = result && (BitVecGet(&bv, 1) == false);
result = result && (BitVecGet(&bv, 500) == false);- In
Insert.c:295:
// Test inserting empty pattern (should be no-op)
BitVecInsertPattern(&bv, 0, 0x00, 0);
result = result && (BitVecLen(&bv) == 0);
// Test inserting single bit pattern
- In
Insert.c:299:
// Test inserting single bit pattern
BitVecInsertPattern(&bv, 0, 0x01, 1); // 1 bit pattern
result = result && (BitVecLen(&bv) == 1);
// Test inserting 8-bit pattern
- In
Insert.c:304:
BitVecClear(&bv);
BitVecInsertPattern(&bv, 0, 0xAA, 8); // 10101010 pattern
result = result && (BitVecLen(&bv) == 8);
result = result && (BitVecGet(&bv, 0) == false); // First bit of 0xAA
result = result && (BitVecGet(&bv, 1) == true); // Second bit
- In
Insert.c:366:
BitVecInsertRange(&bv, 1, 2, false);
bool result = (BitVecLen(&bv) == 6);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false); // inserted
- In
Insert.c:401:
BitVecInsertMultiple(&bv, 1, &other);
bool result = (BitVecLen(&bv) == 5);
result = result && (BitVecGet(&bv, 0) == true); // orig[0]
result = result && (BitVecGet(&bv, 1) == true); // other[0]
- In
Type.c:27:
// Check initial state
bool result =
(BitVecLen(&bitvec) == 0 && BitVecCapacity(&bitvec) == 0 && BitVecData(&bitvec) == NULL &&
BitVecByteSize(&bitvec) == 0);
// Expected result: 1000 (1101 AND 1010)
bool test_result = (BitVecLen(&result) == 4);
test_result = test_result && (BitVecGet(&result, 0) == true);
test_result = test_result && (BitVecGet(&result, 1) == false);
// Expected result: 1110 (1100 OR 1010)
bool test_result = (BitVecLen(&result) == 4);
test_result = test_result && (BitVecGet(&result, 0) == true);
test_result = test_result && (BitVecGet(&result, 1) == true);
// Expected result: 0110 (1100 XOR 1010)
bool test_result = (BitVecLen(&result) == 4);
test_result = test_result && (BitVecGet(&result, 0) == false);
test_result = test_result && (BitVecGet(&result, 1) == true);
// Expected result: 0101 (NOT 1010)
bool test_result = (BitVecLen(&result) == 4);
test_result = test_result && (BitVecGet(&result, 0) == false);
test_result = test_result && (BitVecGet(&result, 1) == true); // After shift left by 2, implementation should clear bits that shift out
// and fill lower positions with 0
bool test_result = (BitVecLen(&bv) == 4);
// Let me trace through the implementation:
BitVecShiftRight(&bv, 2);
bool test_result = (BitVecLen(&bv) == 4);
test_result = test_result && (BitVecGet(&bv, 0) == true);
test_result = test_result && (BitVecGet(&bv, 1) == true);
// Expected result: 1110 (1011 rotated left by 2)
bool test_result = (BitVecLen(&bv) == 4);
test_result = test_result && (BitVecGet(&bv, 0) == true);
test_result = test_result && (BitVecGet(&bv, 1) == true);
// Expected result: 1101 (1011 rotated right by 1)
bool test_result = (BitVecLen(&bv) == 4);
test_result = test_result && (BitVecGet(&bv, 0) == true);
test_result = test_result && (BitVecGet(&bv, 1) == true);
// Expected result: 1101 (1011 reversed)
bool test_result = (BitVecLen(&bv) == 4);
test_result = test_result && (BitVecGet(&bv, 0) == true);
test_result = test_result && (BitVecGet(&bv, 1) == true); // Test shift empty bitvec
BitVecShiftLeft(&bv, 5);
result = result && (BitVecLen(&bv) == 0);
BitVecShiftRight(&bv, 3);
BitVecShiftRight(&bv, 3);
result = result && (BitVecLen(&bv) == 0);
// Test shift by 0 (should be no-op)
BitVecPush(&bv, false);
BitVecShiftLeft(&bv, 0);
result = result && (BitVecLen(&bv) == 2);
result = result && (BitVecGet(&bv, 0) == true); // Test shift larger than length (should clear all bits)
BitVecShiftLeft(&bv, 10);
result = result && (BitVecLen(&bv) == 0); // Should clear when shifting everything out
// Test large data shift
}
BitVecShiftLeft(&bv, 1);
result = result && (BitVecLen(&bv) == 1000);
BitVecDeinit(&bv); // Test rotate empty bitvec
BitVecRotateLeft(&bv, 5);
result = result && (BitVecLen(&bv) == 0);
// Test rotate by 0
BitVecPush(&bv, false);
BitVecRotateLeft(&bv, 2);
result = result && (BitVecLen(&bv) == 2);
// Test large rotate amount
// Test large rotate amount
BitVecRotateRight(&bv, 1000);
result = result && (BitVecLen(&bv) == 2);
BitVecDeinit(&bv); BitVec result_bv = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecAnd(&result_bv, &bv1, &bv2);
result = result && (BitVecLen(&result_bv) == 0);
BitVecOr(&result_bv, &bv1, &bv2);
BitVecOr(&result_bv, &bv1, &bv2);
result = result && (BitVecLen(&result_bv) == 0);
// Test operations with different lengths
BitVecAnd(&result_bv, &bv1, &bv2);
result = result && (BitVecLen(&result_bv) >= 1); // Should handle gracefully
// Test NOT on various sizes
BitVecClear(&bv1);
BitVecNot(&result_bv, &bv1);
result = result && (BitVecLen(&result_bv) == 0);
BitVecPush(&bv1, true); // Test reverse empty bitvec
BitVecReverse(&bv);
result = result && (BitVecLen(&bv) == 0);
// Test reverse single bit
BitVecPush(&bv, true);
BitVecReverse(&bv);
result = result && (BitVecLen(&bv) == 1);
result = result && (BitVecGet(&bv, 0) == true); // Test AND with different lengths (result should be min length)
BitVecAnd(&result, &bv1, &bv2);
test_result = test_result && (BitVecLen(&result) == 4);
// Test OR with different lengths (result should be max length)
// Test OR with different lengths (result should be max length)
BitVecOr(&result, &bv1, &bv2);
test_result = test_result && (BitVecLen(&result) == 8);
// Test XOR with different lengths
// Test XOR with different lengths
BitVecXor(&result, &bv1, &bv2);
test_result = test_result && (BitVecLen(&result) == 8);
// Test with single bit operands
BitVecAnd(&result, &bv1, &bv2);
test_result = test_result && (BitVecLen(&result) == 1);
test_result = test_result && (BitVecGet(&result, 0) == false);
BitVecNot(&result, &bv1);
test_result = test_result && (BitVecLen(&result) == 100);
// Verify NOT correctness
// Should be different from original (lost MSB, gained LSB zero)
bool changed = false;
for (int i = 0; i < (int)BitVecLen(&original); i++) {
if (BitVecGet(&bv, i) != BitVecGet(&original, i)) {
changed = true;
BitVecShiftLeft(&bv, 8);
result = result && (BitVecLen(&bv) == 0);
// Test shifting by more than length
BitVecShiftRight(&bv, 10);
result = result && (BitVecLen(&bv) == 0);
// Test boundary conditions - shift by length-1
BitVecShiftLeft(&bv, 2);
result = result && (BitVecLen(&bv) == 3);
result = result && (BitVecGet(&bv, 0) == false); // filled with 0
result = result && (BitVecGet(&bv, 1) == false); // filled with 0
// Test A XOR A = 0
BitVecXor(&result, &bv1, &bv1);
test_result = test_result && (BitVecLen(&result) == 16);
for (int i = 0; i < 16; i++) {
test_result = test_result && (BitVecGet(&result, i) == false); // Test AND on large data
BitVecAnd(&result, &bv1, &bv2);
test_result = test_result && (BitVecLen(&result) == 1000);
// Verify result integrity - spot check a few positions
// Test XOR on large data
BitVecXor(&result, &bv1, &bv2);
test_result = test_result && (BitVecLen(&result) == 1000);
// Test NOT on large data
// Test NOT on large data
BitVecNot(&result, &bv1);
test_result = test_result && (BitVecLen(&result) == 1000);
// Verify NOT correctness on sample
BitVecShiftLeft(&result, 100);
test_result = test_result && (BitVecLen(&result) == 1000);
// First 100 bits should be 0
// Expected OR (a padded with zeros): 1110
bool ok = (BitVecLen(&result) == 4);
ok = ok && (BitVecGet(&result, 0) == true);
ok = ok && (BitVecGet(&result, 1) == true);
// Expected XOR (a padded with zeros): 1110
bool ok = (BitVecLen(&result) == 4);
ok = ok && (BitVecGet(&result, 0) == true);
ok = ok && (BitVecGet(&result, 1) == true); BitVecShiftRight(&bv, 8);
bool result = (BitVecLen(&bv) == 0);
BitVecDeinit(&bv);
// Correctness sanity: 1011 rotated right by 1 -> 1101.
bool ok = (BitVecLen(&bv) == 4);
ok = ok && (BitVecGet(&bv, 0) == true);
ok = ok && (BitVecGet(&bv, 1) == true);
// Correctness sanity: 1011 rotated left by 2 -> 1110.
bool ok = (BitVecLen(&bv) == 4);
ok = ok && (BitVecGet(&bv, 0) == true);
ok = ok && (BitVecGet(&bv, 1) == true);
// 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); u64 replacements = BitVecReplaceAll(&source, &old_pattern, &new_pattern);
result = result && (replacements == 0);
result = result && (BitVecLen(&source) == 4);
result = result && (BitVecGet(&source, 0) == false);
result = result && (BitVecGet(&source, 3) == false); u64 replacements = BitVecReplaceAll(&source, &old_pattern, &new_pattern);
result = result && (replacements == 1);
result = result && (BitVecLen(&source) == 4); // 5 - 3 + 2
BitVecDeinit(&source); u64 n = BitVecReplaceAll(&source, &old, &neww);
result = result && (n == 0);
result = result && (BitVecLen(&source) == 4);
for (u64 i = 0; i < 4; i++)
result = result && (BitVecGet(&source, i) == false); u64 n = BitVecReplaceAll(&source, &old, &neww);
result = result && (n == 3);
result = result && (BitVecLen(&source) == 6);
// result 010101: position 0 must be 0 (false), position 1 must be 1.
result = result && (BitVecGet(&source, 0) == false);- In
Remove.c:50:
// Check result
bool result = (popped == true) && (BitVecLen(&bv) == 2);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);- In
Remove.c:56:
// Pop another bit
popped = BitVecPop(&bv);
result = result && (popped == false) && (BitVecLen(&bv) == 1);
result = result && (BitVecGet(&bv, 0) == true);- In
Remove.c:61:
// Pop the last bit
popped = BitVecPop(&bv);
result = result && (popped == true) && (BitVecLen(&bv) == 0);
// Clean up
- In
Remove.c:90:
// Check result: true, false, false, true
bool result = (removed == true) && (BitVecLen(&bv) == 4);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);- In
Remove.c:98:
// Remove bit at index 0 (first bit)
removed = BitVecRemove(&bv, 0);
result = result && (removed == true) && (BitVecLen(&bv) == 3);
result = result && (BitVecGet(&bv, 0) == false);
result = result && (BitVecGet(&bv, 1) == false);- In
Remove.c:131:
// Check result: true, false, true (removed false, true, true)
bool result = (BitVecLen(&bv) == 3);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);- In
Remove.c:163:
// Check result: true, true, false, true (removed first false at index 1)
bool result = (found == true) && (BitVecLen(&bv) == 4);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == true);- In
Remove.c:175:
// Now try to remove false from a bitvector with only trues
found = BitVecRemoveFirst(&bv, false);
result = result && (found == false) && (BitVecLen(&bv) == 3);
// Clean up
- In
Remove.c:204:
// Check result: true, false, true, true (removed last false at index 3)
bool result = (found == true) && (BitVecLen(&bv) == 4);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);- In
Remove.c:214:
// Check result: true, false, true (removed last true at index 3)
result = result && (found == true) && (BitVecLen(&bv) == 3);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);- In
Remove.c:247:
// Check result: true, true, true (all false bits removed)
bool result = (removed_count == 3) && (BitVecLen(&bv) == 3);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == true);- In
Remove.c:254:
// Try to remove all false bits again (should return 0)
removed_count = BitVecRemoveAll(&bv, false);
result = result && (removed_count == 0) && (BitVecLen(&bv) == 3);
// Remove all true bits
- In
Remove.c:258:
// Remove all true bits
removed_count = BitVecRemoveAll(&bv, true);
result = result && (removed_count == 3) && (BitVecLen(&bv) == 0);
// Clean up
- In
Remove.c:280:
BitVecPush(&bv, true);
bool popped = BitVecPop(&bv);
result = result && (popped == true) && (BitVecLen(&bv) == 0);
// Test multiple pops in sequence
- In
Remove.c:289:
popped = BitVecPop(&bv);
result = result && (popped == (i % 2 == 0));
result = result && (BitVecLen(&bv) == (size)i);
}- In
Remove.c:308:
BitVecPush(&bv, true);
bool removed = BitVecRemove(&bv, 0);
result = result && (removed == true) && (BitVecLen(&bv) == 0);
// Test remove from large bitvec
- In
Remove.c:318:
removed = BitVecRemove(&bv, 500);
result = result && (removed == (500 % 3 == 0)); // Should return the value of the removed bit
result = result && (BitVecLen(&bv) == 999);
BitVecDeinit(&bv);- In
Remove.c:336:
BitVecPush(&bv, true);
BitVecRemoveRange(&bv, 0, 0);
result = result && (BitVecLen(&bv) == 1);
// Test remove entire bitvec
- In
Remove.c:344:
}
BitVecRemoveRange(&bv, 0, 10);
result = result && (BitVecLen(&bv) == 0);
// Test remove partial range
- In
Remove.c:351:
}
BitVecRemoveRange(&bv, 1, 5); // Remove 5 elements starting at index 1
result = result && (BitVecLen(&bv) == 5); // Should have 5 elements left
BitVecDeinit(&bv);- In
Remove.c:368:
// Test remove from empty bitvec
bool found = BitVecRemoveFirst(&bv, true);
result = result && (found == false) && (BitVecLen(&bv) == 0);
found = BitVecRemoveLast(&bv, false);- In
Remove.c:371:
found = BitVecRemoveLast(&bv, false);
result = result && (found == false) && (BitVecLen(&bv) == 0);
// Test remove when value doesn't exist
- In
Remove.c:377:
BitVecPush(&bv, true);
found = BitVecRemoveFirst(&bv, false);
result = result && (found == false) && (BitVecLen(&bv) == 2);
// Test remove single occurrence
- In
Remove.c:383:
BitVecPush(&bv, false);
found = BitVecRemoveFirst(&bv, false);
result = result && (found == true) && (BitVecLen(&bv) == 0);
// Test remove from large uniform data
- In
Remove.c:390:
}
found = BitVecRemoveFirst(&bv, true);
result = result && (found == true) && (BitVecLen(&bv) == 999);
BitVecDeinit(&bv);- In
Remove.c:407:
// Test remove all from empty bitvec
u64 count = BitVecRemoveAll(&bv, true);
result = result && (count == 0) && (BitVecLen(&bv) == 0);
// Test remove all when value doesn't exist
- In
Remove.c:413:
BitVecPush(&bv, true);
count = BitVecRemoveAll(&bv, false);
result = result && (count == 0) && (BitVecLen(&bv) == 2);
// Test remove all of uniform data
- In
Remove.c:421:
}
count = BitVecRemoveAll(&bv, true);
result = result && (count == 100) && (BitVecLen(&bv) == 0);
// Test remove all mixed data
- In
Remove.c:428:
}
count = BitVecRemoveAll(&bv, false); // Remove odds
result = result && (count == 500) && (BitVecLen(&bv) == 500);
BitVecDeinit(&bv);- In
Remove.c:533:
BitVecRemoveRange(&bv, 2, 100);
bool result = (BitVecLen(&bv) == 2);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == true);- In
Remove.c:564:
BitVecRemoveRange(&bv, 2, 10);
bool result = (BitVecLen(&bv) == 2);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == true);- In
Remove.c:593:
BitVecRemoveRange(&bv, 2, 3);
bool result = (BitVecLen(&bv) == 7);
result = result && (BitVecGet(&bv, 0) == true); // orig[0]
result = result && (BitVecGet(&bv, 1) == false); // orig[1]
- In
Convert.c:83:
// Check result
bool result = ok && (BitVecLen(&bv) == 4);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);- In
Convert.c:91:
// Test with empty string
BitVec empty_bv = BitVecFromStr("", ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&empty_bv) == 0);
// Clean up
- In
Convert.c:149:
// Check result (8 bits from 1 byte)
bool result = ok && (BitVecLen(&bv) == 8);
// 0xB3 = 10110011 has a fixed popcount regardless of bit order, so the
- In
Convert.c:157:
u64 false_count = 0;
for (u64 i = 0; i < BitVecLen(&bv); i++) {
if (BitVecGet(&bv, i)) {
true_count++;- In
Convert.c:227:
// Check result
bool result = ok && (BitVecLen(&bv) == 4);
// Count ones and zeros
- In
Convert.c:233:
u64 false_count = 0;
for (u64 i = 0; i < BitVecLen(&bv); i++) {
if (BitVecGet(&bv, i)) {
true_count++;- In
Convert.c:247:
BitVec zero_bv;
result = result && BitVecTryFromInteger(&zero_bv, 0, 8, ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&zero_bv) == 8);
// All bits should be false
- In
Convert.c:251:
// All bits should be false
bool all_false = true;
for (u64 i = 0; i < BitVecLen(&zero_bv); i++) {
if (BitVecGet(&zero_bv, i)) {
all_false = false;- In
Convert.c:304:
u8 dummy_bytes[1] = {0xFF};
BitVec empty_bv = BitVecFromBytes(dummy_bytes, 0, ALLOCATOR_OF(&alloc));
bool result = (BitVecLen(&empty_bv) == 0);
BitVecDeinit(&empty_bv);- In
Convert.c:356:
// Test empty string
BitVec bv1 = BitVecFromStr("", ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&bv1) == 0);
BitVecDeinit(&bv1);- In
Convert.c:361:
// Test single character
BitVec bv2 = BitVecFromStr("1", ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&bv2) == 1);
result = result && (BitVecGet(&bv2, 0) == true);
BitVecDeinit(&bv2);- In
Convert.c:373:
BitVec bv3 = BitVecFromStr(long_str, ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&bv3) == 1000);
result = result && (BitVecGet(&bv3, 0) == true);
result = result && (BitVecGet(&bv3, 1) == false);- In
Convert.c:399:
u8 empty_bytes[1] = {0x05};
BitVec bv2 = BitVecFromBytes(empty_bytes, 0, ALLOCATOR_OF(&alloc)); // 0 bits
result = result && (BitVecLen(&bv2) == 0);
BitVecDeinit(&bv2);- In
Convert.c:405:
u8 single_byte[1] = {0xFF};
BitVec bv3 = BitVecFromBytes(single_byte, 8, ALLOCATOR_OF(&alloc)); // 8 bits from 1 byte
result = result && (BitVecLen(&bv3) == 8);
BitVecDeinit(&bv3);- In
Convert.c:427:
// Test integer to bitvec with 0
BitVec bv2 = BitVecFromInteger(0, 8, ALLOCATOR_OF(&alloc)); // 8 bits for zero
result = result && (BitVecLen(&bv2) == 8); // Should be 8 bits
BitVecDeinit(&bv2);- In
Convert.c:432:
// Test large integer
BitVec bv3 = BitVecFromInteger(UINT64_MAX, 64, ALLOCATOR_OF(&alloc)); // 64 bits for max value
result = result && (BitVecLen(&bv3) == 64);
BitVecDeinit(&bv3);- In
Convert.c:513:
// Test large integer conversion (should cap at 64 bits)
BitVec large_bv = BitVecFromInteger(0xFFFFFFFFFFFFFFFF, 64, ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&large_bv) == 64);
u64 large_value = BitVecToInteger(&large_bv);- In
Convert.c:675:
// Test round-trip from bytes
BitVec recovered_bv = BitVecFromBytes(large_bytes, 1000, ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&recovered_bv) == 1000);
// Verify recovered pattern
- In
Convert.c:679:
// Verify recovered pattern
bool recovered_pattern_correct = true;
for (u64 i = 0; i < BitVecLen(&recovered_bv); i++) {
bool expected = (i % 3) == 0;
bool actual = BitVecGet(&recovered_bv, i);- In
Convert.c:700:
BitVec large_from_str = BitVecFromStr(large_pattern, ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&large_from_str) == 2000);
// Verify pattern
- In
Convert.c:704:
// Verify pattern
bool large_pattern_correct = true;
for (u64 i = 0; i < BitVecLen(&large_from_str); i++) {
bool expected = (i % 7) == 0;
bool actual = BitVecGet(&large_from_str, i);- In
Convert.c:801:
bool ok = BitVecTryFromInteger(&bv, 0xFFu, 100, ALLOCATOR_OF(&alloc));
bool result = ok && (BitVecLen(&bv) == 64);
BitVecDeinit(&bv);- In
Convert.c:901:
Str s = StrInitFromZstr("111000111", &alloc);
BitVec bv = bitvec_from_str_str(&s, ALLOCATOR_OF(&alloc));
bool result = (BitVecLen(&bv) == 9) && (BitVecCountOnes(&bv) == 6);
for (int i = 0; i < 9; i++) {
result = result && (BitVecGet(&bv, i) == ((i / 3) % 2 == 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);- In
Type.c:90:
bool result =
BitVecLen(&clone.bits) == BitVecLen(&original.bits) && IntAllocator(&clone) == IntAllocator(&original) &&
IntAllocator(&clone)->allocate == IntAllocator(&original)->allocate &&
IntAllocator(&clone)->remap == IntAllocator(&original)->remap &&- In
Write.c:1417:
StrReadFmt(z, "{}", bv);
bool ok = (BitVecToInteger(&bv) == 1) && (BitVecLen(&bv) == 4);
BitVecDeinit(&bv);- In
Write.c:1435:
StrReadFmt(z, "{}", bv);
bool ok = (BitVecToInteger(&bv) == 0xDEAD) && (BitVecLen(&bv) == 16);
BitVecDeinit(&bv);- In
Write.c:1470:
StrReadFmt(z, "{}", bv);
bool ok = (BitVecToInteger(&bv) == 1) && (BitVecLen(&bv) == 3);
BitVecDeinit(&bv);- In
Write.c:1506:
StrReadFmt(z, "{}", bv);
bool ok = (BitVecToInteger(&bv) == 0755) && (BitVecLen(&bv) == 9);
BitVecDeinit(&bv);- In
Write.c:2494:
StrReadFmt(z, "{}", bv);
bool ok = (BitVecLen(&bv) == 10) && (BitVecToInteger(&bv) == 0x3ff);
BitVecDeinit(&bv);- In
Write.c:2513:
StrReadFmt(z, "{}", bv);
bool ok = (BitVecLen(&bv) == 8) && (BitVecToInteger(&bv) == 0xff);
BitVecDeinit(&bv);- In
Write.c:2532:
StrReadFmt(z, "{}", bv);
bool ok = (BitVecLen(&bv) == 17) && (BitVecToInteger(&bv) == 0x10000);
BitVecDeinit(&bv);- In
Read.c:2516:
Zstr z = "0x1";
StrReadFmt(z, "{}", bv);
bool ok = (BitVecToInteger(&bv) == 1) && (BitVecLen(&bv) == 4); // min-width clamp
BitVecDeinit(&bv);
ok = ok && (DebugAllocatorLiveCount(&dbg) == 0);- In
Read.c:2529:
Zstr z = "0xDEAD";
StrReadFmt(z, "{}", bv);
bool ok = (BitVecToInteger(&bv) == 0xDEAD) && (BitVecLen(&bv) == 16);
BitVecDeinit(&bv);
DefaultAllocatorDeinit(&alloc);- In
Read.c:2541:
Zstr z = "0o1";
StrReadFmt(z, "{}", bv);
bool ok = (BitVecToInteger(&bv) == 1) && (BitVecLen(&bv) == 3);
BitVecDeinit(&bv);
ok = ok && (DebugAllocatorLiveCount(&dbg) == 0);- In
Read.c:2554:
Zstr z = "10110";
StrReadFmt(z, "{}", bv);
bool ok = (BitVecLen(&bv) == 5) && (BitVecToInteger(&bv) == 13);
BitVecDeinit(&bv);
ok = ok && (DebugAllocatorLiveCount(&dbg) == 0);
Last updated on