BitVecSwap
- Function
- August 22, 2025
Table of Contents
BitVecSwap
BitVecSwap
Description
Efficiently swap the contents of two bitvectors. This is much faster than copying both bitvectors.
Parameters
Name | Direction | Description |
---|---|---|
bv1 | in | First bitvector |
bv2 | in | Second bitvector |
Usage example (from documentation)
BitVecSwap(&flags1, &flags2); // Swap contents
Usage example (Cross-references)
- In
BitVec.c:143
:
void BitVecSwap(BitVec *bv1, BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2);
// Test BitVecSwap function
bool test_bitvec_swap(void) {
printf("Testing BitVecSwap\n");
BitVec bv1 = BitVecInit();
// Swap the bitvectors
BitVecSwap(&bv1, &bv2);
// Check that they swapped
bool test_bitvec_swap_edge_cases(void) {
printf("Testing BitVecSwap edge cases\n");
BitVec bv1 = BitVecInit();
// Test swap with both empty
BitVecSwap(&bv1, &bv2);
result = result && (bv1.length == 0) && (bv2.length == 0);
BitVecPush(&bv1, true);
BitVecPush(&bv1, false);
BitVecSwap(&bv1, &bv2);
result = result && (bv1.length == 0);
}
BitVecSwap(&bv1, &bv2);
result = result && (bv1.length == 2) && (bv2.length == 1000);
result = result && (BitVecGet(&bv2, 0) == true); // 0 % 3 == 0
// Test swapping with itself (should be safe)
BitVecSwap(&bv1, &bv1);
result = result && (bv1.length == 2);
// Clone and swap
BitVec clone = BitVecClone(&bv1);
BitVecSwap(&bv1, &bv2);
// Reu64 operations
// Test NULL pointer - should abort
BitVecSwap(NULL, &bv);
BitVecDeinit(&bv);