BitVecWeightCompare

Table of Contents

BitVecWeightCompare

Description

Compare two bitvectors by their Hamming weights (number of 1s).

Parameters

NameDirectionDescription
bv1inFirst bitvector
bv2inSecond bitvector

Usage example (from documentation)

  int result = BitVecWeightCompare(&flags1, &flags2);

Usage example (Cross-references)

    }
    
    int BitVecWeightCompare(BitVec *bv1, BitVec *bv2) {
    ValidateBitVec(bv1);
    ValidateBitVec(bv2);
    // Test BitVecWeightCompare function
    bool test_bitvec_weight_compare(void) {
    WriteFmt("Testing BitVecWeightCompare\n");
    
    BitVec bv1 = BitVecInit();
    
    // Weight comparison should compare number of set bits
    int  cmp_result = BitVecWeightCompare(&bv1, &bv2);
    bool result     = (cmp_result > 0); // 3 ones > 2 ones
    BitVecPush(&bv2, true); // Also 3 ones
    
    result = result && (BitVecWeightCompare(&bv1, &bv2) == 0);
    
    // Clean up
    
    // Weight: bv1 has 4 ones, bv2 has 4 ones, so equal weight
    result = result && (BitVecWeightCompare(&bv1, &bv2) == 0);
    
    // Lexicographic comparison

Share :

Related Posts

BitVecIsSubset

BitVecIsSubset Description Check if first bitvector is a subset of the second. A bitvector is a subset if all its 1-bits are also 1-bits in the other.

Read More

BitVecFromInteger

BitVecFromInteger Description Create bitvector from integer value. Creates a bitvector representing the specified number of bits from the integer.

Read More

BitVecDisjoint

BitVecDisjoint Description Check if two bitvectors are disjoint (have no common 1-bits).

Read More