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

BitVecNumericalCompare

BitVecNumericalCompare Description Compare two bitvectors as unsigned integers. Treats bitvectors as unsigned binary numbers (LSB first).

Read More

BitVecCompare

BitVecCompare Description Compare two bitvectors lexicographically. Comparison is done bit by bit from left to right.

Read More

BitVecIsSorted

BitVecIsSorted Description Check if bits in bitvector are in sorted order. Useful for certain algorithms and data structures.

Read More