BitVecOverlaps

Table of Contents

BitVecOverlaps

Description

Check if two bitvectors overlap (have any common 1-bits).

Parameters

NameDirectionDescription
bv1inFirst bitvector
bv2inSecond bitvector

Usage example (from documentation)

  bool overlaps = BitVecOverlaps(&set1, &set2);

Usage example (Cross-references)

    }
    
    bool BitVecOverlaps(BitVec *bv1, BitVec *bv2) {
    return !BitVecDisjoint(bv1, bv2);
    }
    // Test BitVecOverlaps function
    bool test_bitvec_overlaps(void) {
    printf("Testing BitVecOverlaps\n");
    
    BitVec bv1 = BitVecInit();
    
    // They overlap at position 0 (both have 1)
    bool result = BitVecOverlaps(&bv1, &bv2);
    
    // Test non-overlapping bitvectors
    
    // They should not overlap (no position where both have 1)
    result = result && !BitVecOverlaps(&bv1, &bv2);
    
    // Clean up
    // Should be disjoint and not intersect
    bool result = BitVecDisjoint(&bv1, &bv2);
    result      = result && !BitVecOverlaps(&bv1, &bv2);
    
    // Create intersecting bitvectors
    // Should not be disjoint and should intersect
    result = result && !BitVecDisjoint(&bv1, &bv2);
    result = result && BitVecOverlaps(&bv1, &bv2);
    
    // Test with empty bitvectors
    BitVecClear(&bv2);
    result = result && BitVecDisjoint(&bv1, &bv2);
    result = result && !BitVecOverlaps(&bv1, &bv2);
    
    // Clean up
    
    // Test with empty sets
    result = result && !BitVecOverlaps(&bv1, &bv2);
    result = result && BitVecDisjoint(&bv1, &bv2);
    BitVecPush(&bv1, true);
    BitVecPush(&bv2, false);
    result = result && !BitVecOverlaps(&bv1, &bv2);
    
    // Test large sets
    }
    // Should have some overlap since both contain position 0 (true)
    result = result && BitVecOverlaps(&bv1, &bv2);
    
    BitVecDeinit(&bv1);
    
    // Test set operations on large vectors
    bool overlaps = BitVecOverlaps(&large1, &large2);
    bool disjoint = BitVecDisjoint(&large1, &large2);
    result        = result && (overlaps != disjoint); // Should be opposite

Share :

Related Posts

BitVecShiftLeft

BitVecShiftLeft Description Shift all bits in bitvector to the left by specified positions. New bits on the right 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

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