BitVecEqualsRange

Table of Contents

BitVecEqualsRange

Description

Compare specific ranges of two bitvectors for equality.

Parameters

NameDirectionDescription
bv1inFirst bitvector
start1inStarting position in first bitvector
bv2inSecond bitvector
start2inStarting position in second bitvector
leninNumber of bits to compare

Usage example (from documentation)

  bool equal = BitVecEqualsRange(&bv1, 5, &bv2, 10, 8);

Usage example (Cross-references)

    }
    
    return BitVecEqualsRange(bv1, 0, bv2, 0, bv1->length);
    }
    }
    
    bool BitVecEqualsRange(BitVec *bv1, u64 start1, BitVec *bv2, u64 start2, u64 len) {
    ValidateBitVec(bv1);
    ValidateBitVec(bv2);
    // Test BitVecEqualsRange function
    bool test_bitvec_equals_range(void) {
    printf("Testing BitVecEqualsRange\n");
    
    BitVec bv1 = BitVecInit();
    // Test unequal ranges
    // bv1[3:5] = 000, bv2[1:3] = 010, should be false
    bool result = !BitVecEqualsRange(&bv1, 3, &bv2, 1, 3);
    
    // Test equal ranges that actually match
    
    // Test equal ranges that actually match
    result = result && BitVecEqualsRange(&bv1, 0, &bv1, 0, 8); // Self-equality
    
    // Test equal ranges with same pattern
    // Test equal ranges with same pattern
    // bv1[3:5] = 000, bv2[3:5] = 001, should be false
    result = result && !BitVecEqualsRange(&bv1, 3, &bv2, 3, 3);
    
    // Test actually equal ranges: bv1[3:4] = 00, bv2[0:1] = 00
    
    // Test actually equal ranges: bv1[3:4] = 00, bv2[0:1] = 00
    result = result && BitVecEqualsRange(&bv1, 3, &bv2, 0, 2);
    
    // Test boundary conditions
    
    // Test boundary conditions
    result = result && BitVecEqualsRange(&bv1, 0, &bv2, 0, 0); // Zero length (should be true)
    
    // Clean up
    
    // Test range operations on large vectors
    result = result && BitVecEqualsRange(&large1, 100, &large1, 100, 500); // Self-range equality
    
    // Test set operations on large vectors
    
    // Test NULL pointer in range operations - should abort
    BitVecEqualsRange(NULL, 0, &bv, 0, 1);
    
    BitVecDeinit(&bv);
    
    // Test out-of-bounds range - should abort
    BitVecEqualsRange(&bv1, 0, &bv2, 0, 5); // Range exceeds length
    
    BitVecDeinit(&bv1);

Share :

Related Posts

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

BitVecRemoveRange

BitVecRemoveRange Description Remove multiple consecutive bits starting at a specific position. All bits after the removed range are shifted left.

Read More

BitVecRotateLeft

BitVecRotateLeft Description Rotate all bits in bitvector to the left by specified positions. Bits that fall off the left end wrap around to the right.

Read More