BitVecSwap

Table of Contents

BitVecSwap

Description

Efficiently swap the contents of two bitvectors. This is much faster than copying both bitvectors.

Parameters

NameDirectionDescription
bv1inFirst bitvector
bv2inSecond bitvector

Usage example (from documentation)

  BitVecSwap(&flags1, &flags2);  // Swap contents

Usage example (Cross-references)

    
    
    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);

Share :

Related Posts

BitVecReplaceAll

BitVecReplaceAll Description Replace all occurrences of old pattern with new pattern.

Read More

BitVecDeinit

BitVecDeinit Description Deinitialize bitvector and free all allocated memory. After calling this, the bitvector should not be used unless re-initialized.

Read More

BitVecMatches

BitVecMatches Description Match bitvector against pattern with wildcards. Wildcards allow flexible pattern matching where some positions can be “any bit”.

Read More