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) {
    WriteFmt("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

BitVecRemoveFirst

BitVecRemoveFirst Description Remove the first occurrence of a specific bit value. Returns true if a bit was found and removed, false otherwise.

Read More

BitVecRemoveLast

BitVecRemoveLast Description Remove the last occurrence of a specific bit value. Returns true if a bit was found and removed, false otherwise.

Read More

BitVecIsSuperset

BitVecIsSuperset Description Check if first bitvector is a superset of the second. A bitvector is a superset if it contains all 1-bits from the other.

Read More