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)
Usage examples (Cross-references)
- In
BitVec.c:143:
void BitVecSwap(BitVec *bv1, BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2); // Test BitVecSwap function
bool test_bitvec_swap(void) {
WriteFmt("Testing BitVecSwap\n");
BitVec bv1 = BitVecInit();
// Swap the bitvectors
BitVecSwap(&bv1, &bv2);
// Check that they swapped
bool test_bitvec_swap_edge_cases(void) {
WriteFmt("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);
Last updated on