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);Success
true if bv1 is a subset of bv2
Failure
false when any 1-bit of bv1 is not also set in bv2.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:770:
}
bool BitVecIsSubset(const BitVec *bv1, const BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2);- In
BitVec.c:792:
bool BitVecIsSuperset(const BitVec *bv1, const BitVec *bv2) {
return BitVecIsSubset(bv2, bv1);
} DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecIsSubset\n");
BitVec subset = BitVecInit(ALLOCATOR_OF(&alloc));
// 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