BitVecCompareRange

Table of Contents

BitVecCompareRange

Description

Compare ranges of two bitvectors lexicographically.

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)

  int result = BitVecCompareRange(&bv1, 5, &bv2, 10, 8);

Usage example (Cross-references)

    
    // Compare common bits using range comparison
    int range_result = BitVecCompareRange(bv1, 0, bv2, 0, min_len);
    if (range_result != 0) {
    return range_result;
    }
    
    int BitVecCompareRange(BitVec *bv1, u64 start1, BitVec *bv2, u64 start2, u64 len) {
    ValidateBitVec(bv1);
    ValidateBitVec(bv2);
    // Test BitVecCompareRange function
    bool test_bitvec_compare_range(void) {
    printf("Testing BitVecCompareRange\n");
    
    BitVec bv1 = BitVecInit();
    
    // Test range comparisons
    int  cmp_result = BitVecCompareRange(&bv1, 2, &bv2, 2, 3); // Compare 3-bit ranges
    bool result     = (cmp_result != 0);                       // Should not be equal
    
    // Test equal ranges
    cmp_result = BitVecCompareRange(&bv1, 0, &bv1, 0, 8); // Self-comparison
    result     = result && (cmp_result == 0);
    
    // Test zero-length ranges
    cmp_result = BitVecCompareRange(&bv1, 0, &bv2, 0, 0);
    result     = result && (cmp_result == 0); // Zero-length ranges are equal

Share :

Related Posts

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

BitVecReverse

BitVecReverse Description Reverse the order of all bits in bitvector. First bit becomes last, last becomes first, etc.

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