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:825:
}
bool BitVecIsSubset(const BitVec *bv1, const BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2);- In
BitVec.c:847:
bool BitVecIsSuperset(const BitVec *bv1, const BitVec *bv2) {
return BitVecIsSubset(bv2, bv1);
}- In
Compare.c:257:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecIsSubset\n");
BitVec subset = BitVecInit(ALLOCATOR_OF(&alloc));- In
Compare.c:275:
// 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
- In
Compare.c:280:
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)
- In
Compare.c:289:
BitVecPush(&superset, false);
result = result && BitVecIsSubset(&subset, &superset);
// Clean up
- In
Compare.c:708:
BitVecClear(&bv1);
BitVecClear(&bv2);
result = result && BitVecIsSubset(&bv1, &bv2); // Empty is subset of empty
BitVecDeinit(&bv1);- In
Compare.c:810:
BitVecPush(&superset, true);
result = result && BitVecIsSubset(&subset, &superset);
result = result && BitVecIsSuperset(&superset, &subset);- In
Compare.c:912:
// Test NULL pointer - should abort
BitVecIsSubset(NULL, NULL);
return false;- In
Compare.c:1554:
BitVecPush(&bv, true);
BitVecIsSubset(NULL, &bv); // must abort
BitVecDeinit(&bv);- In
Compare.c:1569:
Allocator *base = ALLOCATOR_OF(&alloc);
WriteFmt("Testing BitVecIsSubset scans past index 42\n");
BitVec bv1 = BitVecInit(base);- In
Compare.c:1580:
// bv1's 1-bit at 45 has no counterpart in bv2 -> not a subset.
bool result = (BitVecIsSubset(&bv1, &bv2) == false);
BitVecDeinit(&bv1);- In
Compare.c:1596:
Allocator *base = ALLOCATOR_OF(&alloc);
WriteFmt("Testing BitVecIsSubset with shorter bv1 stays in bounds\n");
BitVec bv1 = BitVecInit(base); // length 2
- In
Compare.c:1611:
// bv1's only 1 (pos 0) is set in bv2 -> subset is true.
bool result = (BitVecIsSubset(&bv1, &bv2) == true);
BitVecDeinit(&bv1);- In
Compare.c:1627:
Allocator *base = ALLOCATOR_OF(&alloc);
WriteFmt("Testing BitVecIsSubset with shorter bv2 stays in bounds\n");
BitVec bv1 = BitVecInit(base); // length 5
- In
Compare.c:1642:
// bv1's only 1 (pos 0) is set in bv2 -> subset is true.
bool result = (BitVecIsSubset(&bv1, &bv2) == true);
BitVecDeinit(&bv1);- In
Compare.c:1687:
Allocator *base = ALLOCATOR_OF(&alloc);
WriteFmt("Testing BitVecIsSubset rejects NULL bv2\n");
BitVec bv1 = BitVecInit(base);- In
Compare.c:1693:
// Should abort on the NULL second argument.
BitVecIsSubset(&bv1, NULL);
BitVecDeinit(&bv1);
Last updated on