BitVecIsSubset

Table of Contents

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.

Parameters

NameDirectionDescription
bv1inPotential subset bitvector
bv2inPotential superset bitvector

Usage example (from documentation)

  bool is_subset = BitVecIsSubset(&small_set, &large_set);

Usage example (Cross-references)

    }
    
    bool BitVecIsSubset(BitVec *bv1, BitVec *bv2) {
    ValidateBitVec(bv1);
    ValidateBitVec(bv2);
    
    bool BitVecIsSuperset(BitVec *bv1, BitVec *bv2) {
    return BitVecIsSubset(bv2, bv1);
    }
    // Test BitVecIsSubset function
    bool test_bitvec_is_subset(void) {
    printf("Testing BitVecIsSubset\n");
    
    BitVec subset   = BitVecInit();
    
    // subset should be a subset of superset (all 1s in subset are also 1s in superset)
    bool result = BitVecIsSubset(&subset, &superset);
    
    // Test non-subset case
    BitVecSet(&superset, 2, false); // Change superset to 1101
    // Now subset (1010) is not a subset of superset (1101) because subset has 1 at position 2
    result = result && !BitVecIsSubset(&subset, &superset);
    
    // Test equal sets (should be subset)
    BitVecPush(&superset, false);
    
    result = result && BitVecIsSubset(&subset, &superset);
    
    // Clean up
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    result = result && BitVecIsSubset(&bv1, &bv2); // Empty is subset of empty
    
    BitVecDeinit(&bv1);
    BitVecPush(&superset, true);
    
    result = result && BitVecIsSubset(&subset, &superset);
    result = result && BitVecIsSuperset(&superset, &subset);
    
    // Test NULL pointer - should abort
    BitVecIsSubset(NULL, NULL);
    
    return false;

Share :

Related Posts

BitVecEqualsRange

BitVecEqualsRange Description Compare specific ranges of two bitvectors for equality.

Read More

BitVecShiftRight

BitVecShiftRight Description Shift all bits in bitvector to the right by specified positions. New bits on the left are filled with zeros.

Read More

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