Skip to content
BitVecCompareRange

BitVecCompareRange

BitVecCompareRange

Description

Compare ranges of two bitvectors lexicographically.

Parameters

Name Direction Description
bv1 in First bitvector
start1 in Starting position in first bitvector
bv2 in Second bitvector
start2 in Starting position in second bitvector
len in Number of bits to compare

Usage example (from documentation)

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

Returns

-1 if bv1 < bv2, 0 if equal, 1 if bv1 > bv2

Usage example (Cross-references)

Usage examples (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
Last updated on