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

BitVecRemove

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

Read More

BitVecAlignmentScore

BitVecAlignmentScore Description Calculate alignment score between two bitvectors. Used in bioinformatics-style sequence alignment with match/mismatch scoring.

Read More

BitVecRemoveLast

BitVecRemoveLast Description Remove the last occurrence of a specific bit value. Returns true if a bit was found and removed, false otherwise.

Read More