BitVecEquals

Table of Contents

BitVecEquals

Description

Test equality between two bitvectors. Two bitvectors are equal if they have the same length and all bits match.

Parameters

NameDirectionDescription
bv1inFirst bitvector
bv2inSecond bitvector

Usage example (from documentation)

  bool equal = BitVecEquals(&flags1, &flags2);

Usage example (Cross-references)

    
    // Comparison functions
    bool BitVecEquals(BitVec *bv1, BitVec *bv2) {
    ValidateBitVec(bv1);
    ValidateBitVec(bv2);
    // Test BitVecEquals function
    bool test_bitvec_equals(void) {
    printf("Testing BitVecEquals\n");
    
    BitVec bv1 = BitVecInit();
    
    // Test equal empty bitvectors
    bool result = BitVecEquals(&bv1, &bv2);
    
    // Add same pattern to both
    
    // Should be equal
    result = result && BitVecEquals(&bv1, &bv2);
    
    // Add different pattern to third
    
    // Should not be equal
    result = result && !BitVecEquals(&bv1, &bv3);
    
    // Test different lengths
    // Test different lengths
    BitVecPush(&bv3, true);
    result = result && !BitVecEquals(&bv1, &bv3);
    
    // Clean up
    
    // Test compare empty bitvecs
    result = result && BitVecEquals(&bv1, &bv2);
    result = result && (BitVecCompare(&bv1, &bv2) == 0);
    // Test compare empty vs non-empty
    BitVecPush(&bv1, true);
    result = result && !BitVecEquals(&bv1, &bv2);
    result = result && (BitVecCompare(&bv1, &bv2) != 0);
    BitVecPush(&bv2, bit);
    }
    result = result && BitVecEquals(&bv1, &bv2);
    
    // Test subset operations on empty sets
    
    // Test large-scale comparison performance and correctness
    result = result && (BitVecEquals(&large1, &large1)); // Self-equality
    result = result && !BitVecEquals(&large1, &large2);  // Different patterns
    // Test large-scale comparison performance and correctness
    result = result && (BitVecEquals(&large1, &large1)); // Self-equality
    result = result && !BitVecEquals(&large1, &large2);  // Different patterns
    
    // Test range operations on large vectors
    
    // Test NULL pointer - should abort
    BitVecEquals(NULL, &bv);
    
    BitVecDeinit(&bv);

Share :

Related Posts

BitVecCompareRange

BitVecCompareRange Description Compare ranges of two bitvectors lexicographically.

Read More

BitVecOverlaps

BitVecOverlaps Description Check if two bitvectors overlap (have any common 1-bits).

Read More

BitVecShiftRight

BitVecShiftRight Description Shift all bits in bitvector to the right by specified positions. New bits on the left are filled with zeros.

Read More