Skip to content
BitVecIsSubset

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.

Parameters

Name Direction Description
bv1 in Potential subset bitvector
bv2 in Potential superset bitvector

Usage example (from documentation)

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

Returns

true if bv1 is a subset of bv2

Usage example (Cross-references)

Usage examples (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) {
        WriteFmt("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;
Last updated on