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

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

BitVecRemoveFirst

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

Read More

BitVecInsertRange

BitVecInsertRange Description Insert multiple bits of the same value at a specific position. All existing bits at and after the position are shifted right.

Read More