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) {
    WriteFmt("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

BitVecRemove

BitVecRemove Description Remove a bit at given index from bitvector. Shifts all bits after the index to the left.

Read More

BitVecEqualsRange

BitVecEqualsRange Description Compare specific ranges of two bitvectors for equality.

Read More

BitVecIsSuperset

BitVecIsSuperset Description Check if first bitvector is a superset of the second. A bitvector is a superset if it contains all 1-bits from the other.

Read More