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

Share :

Related Posts

BitVecInsert

BitVecInsert Description Insert a bit at given index in bitvector. Shifts all bits at and after the index to the right.

Read More

BitVecInsertRange

BitVecInsertRange Description Insert multiple bits of the same value at a specific position. All existing bits at and after the position are shifted right.

Read More

BitVecLongestRun

BitVecLongestRun Description Find the longest consecutive sequence of a specific bit value.

Read More