BitVecReverse
Description
Reverse the order of all bits in bitvector. First bit becomes last, last becomes first, etc.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in,out | Bitvector to reverse in place. |
Usage example (from documentation)
BitVecReverse(&flags);Success
Returns to the caller. The bit at index i is now the previous bit at index length - 1 - i. Length and capacity are unchanged.
Failure
Function cannot fail. An invalid bitvector is a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1160:
}
void BitVecReverse(BitVec *bv) {
ValidateBitVec(bv);
if (bv->length <= 1) { DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecReverse\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// Reverse the bits
BitVecReverse(&bv);
// Expected result: 1101 (1011 reversed)
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecReverse edge cases\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// 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); BitVecPush(&bv, true);
BitVecPush(&bv, false);
BitVecReverse(&bv);
result = result && (BitVecGet(&bv, 0) == false);
result = result && (BitVecGet(&bv, 1) == true);
// Test double reverse (should restore original)
BitVecReverse(&bv);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);
// Test NULL pointer - should abort
BitVecReverse(NULL);
return false; DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmtLn("Testing BitVecReverse");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// Reverse the bits
BitVecReverse(&bv);
// Expected result: 1101 (1011 reversed)
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmtLn("Testing BitVecReverse edge cases");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// 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); BitVecPush(&bv, true);
BitVecPush(&bv, false);
BitVecReverse(&bv);
result = result && (BitVecGet(&bv, 0) == false);
result = result && (BitVecGet(&bv, 1) == true);
// Test double reverse (should restore original)
BitVecReverse(&bv);
result = result && (BitVecGet(&bv, 0) == true);
result = result && (BitVecGet(&bv, 1) == false);
// Test NULL pointer - should abort
BitVecReverse(NULL);
return false;
Last updated on