BitVecClear

Table of Contents

BitVecClear

Description

Clear all bits in bitvector without deallocating memory. Sets length to 0 but keeps allocated capacity.

Parameters

NameDirectionDescription
bvinPointer to bitvector to clear

Usage example (from documentation)

  BitVecClear(&flags);

Usage example (Cross-references)

    }
    
    void BitVecClear(BitVec *bitvec) {
    ValidateBitVec(bitvec);
    bitvec->length = 0;
    if (positions >= bv->length) {
    // Shift everything out
    BitVecClear(bv);
    return;
    }
    if (positions >= bv->length) {
    // Shift everything out
    BitVecClear(bv);
    return;
    }
    
    // Test foreach on large data
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test foreach idx ordering
    BitVecClear(&bv);
    for (int i = 0; i < 10; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test reverse ordering
    BitVecClear(&bv);
    BitVecPush(&bv, true);                          // idx 0
    BitVecPush(&bv, false);                         // idx 1
    
    // Test with complex random-like pattern
    BitVecClear(&large_bv);
    
    // Pattern: 1111000011100010000111 (variable length runs)
    // Test BitVecClear function
    bool test_bitvec_clear(void) {
    printf("Testing BitVecClear\n");
    
    BitVec bv = BitVecInit();
    
    // Clear the bitvector
    BitVecClear(&bv);
    
    // Check that length is 0 but capacity and memory allocation remain
    
    bool test_bitvec_clear_edge_cases(void) {
    printf("Testing BitVecClear edge cases\n");
    
    BitVec bv     = BitVecInit();
    
    // Test clear on empty bitvec
    BitVecClear(&bv);
    result = result && (bv.length == 0);
    // Test clear after single bit
    BitVecPush(&bv, true);
    BitVecClear(&bv);
    result = result && (bv.length == 0);
    
    // Test multiple clears
    BitVecClear(&bv);
    BitVecClear(&bv);
    result = result && (bv.length == 0);
    // Test multiple clears
    BitVecClear(&bv);
    BitVecClear(&bv);
    result = result && (bv.length == 0);
    BitVecPush(&bv, i % 2);
    }
    BitVecClear(&bv);
    result = result && (bv.length == 0);
    // Test shrink after reserve and clear
    BitVecReserve(&bv, 1000);
    BitVecClear(&bv);
    BitVecShrinkToFit(&bv);
    result = result && (bv.length == 0);
    // Test set capacity to 0
    // BitVecReserve doesn't support shrinking to 0, use BitVecClear instead
    BitVecClear(&bv);
    result = result && (bv.length == 0);
    
    // Test swap with large data
    BitVecClear(&bv1);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv1, i % 3 == 0);
    
    // Test clone large data
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test all same bits
    BitVecClear(&bv);
    for (int i = 0; i < 100; i++) {
    BitVecPush(&bv, true);
    
    // Test all ones
    BitVecClear(&bv);
    for (int i = 0; i < 64; i++) {
    BitVecPush(&bv, true);
    
    // Test checkerboard pattern
    BitVecClear(&bv);
    for (int i = 0; i < 64; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test sparse pattern (every 8th bit)
    BitVecClear(&bv);
    for (int i = 0; i < 64; i++) {
    BitVecPush(&bv, i % 8 == 0);
    
    // Test random-like pattern (using simple algorithm)
    BitVecClear(&bv);
    for (int i = 0; i < 100; i++) {
    BitVecPush(&bv, (i * 17 + 3) % 7 < 3); // Pseudo-random pattern
    
    // Test with all same values
    BitVecClear(&bv);
    for (int i = 0; i < 5; i++) {
    BitVecPush(&bv, true);
    
    // Test with all false
    BitVecClear(&bv);
    for (int i = 0; i < 5; i++) {
    BitVecPush(&bv, false);
    
    // Test with mixed values
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, false);
    
    // Test with all same values
    BitVecClear(&bv);
    for (int i = 0; i < 10; i++) {
    BitVecPush(&bv, true);
    
    // Test alternating pattern
    BitVecClear(&bv);
    for (int i = 0; i < 10; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test with large bitvector
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, i == 500 || i == 999); // Only indices 500 and 999 are true
    
    // Test large bitvector with specific patterns
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, true); // All true
    
    // Test large runs
    BitVecClear(&bv);
    for (int i = 0; i < 10000; i++) {
    BitVecPush(&bv, true);
    
    // Test large range insertion
    BitVecClear(&bv);
    BitVecInsertRange(&bv, 0, 1000, true);
    result = result && (bv.length == 1000);
    
    // Test inserting large bitvec
    BitVecClear(&source);
    for (int i = 0; i < 500; i++) {
    BitVecPush(&source, false);
    
    // Test inserting 8-bit pattern
    BitVecClear(&bv);
    BitVecInsertPattern(&bv, 0, 0xAA, 8);            // 10101010 pattern
    result = result && (bv.length == 8);
    
    // Test remove entire bitvec
    BitVecClear(&bv);
    for (int i = 0; i < 10; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test remove single occurrence
    BitVecClear(&bv);
    BitVecPush(&bv, false);
    found  = BitVecRemoveFirst(&bv, false);
    
    // Test remove all of uniform data
    BitVecClear(&bv);
    for (int i = 0; i < 100; i++) {
    BitVecPush(&bv, true);
    
    // Test large data shift
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test NOT on various sizes
    BitVecClear(&bv1);
    BitVecNot(&result_bv, &bv1);
    result = result && (result_bv.length == 0);
    
    // Test reverse even length
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, false);
    
    // Test with single bit operands
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    // Test with single bit operands
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    BitVecPush(&bv2, false);
    
    // Test NOT on large bitvector
    BitVecClear(&bv1);
    for (int i = 0; i < 100; i++) {
    BitVecPush(&bv1, i % 3 == 0);
    
    // Test shifting by exactly length (should clear everything)
    BitVecClear(&bv);
    for (int i = 0; i < 8; i++) {
    BitVecPush(&bv, true);
    
    // Test shifting by more than length
    BitVecClear(&bv);
    for (int i = 0; i < 5; i++) {
    BitVecPush(&bv, true);
    
    // Test boundary conditions - shift by length-1
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, true);
    
    // Test rotate with odd length
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, false);
    
    // Test A AND 0 = 0
    BitVecClear(&bv2);
    for (int i = 0; i < 16; i++) {
    BitVecPush(&bv2, false);
    
    // Test A OR 1 = 1
    BitVecClear(&bv2);
    for (int i = 0; i < 16; i++) {
    BitVecPush(&bv2, true);
    
    // Test shift on large data
    BitVecClear(&result);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&result, i % 2 == 0);
    
    // Test large data shift
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test NOT on various sizes
    BitVecClear(&bv1);
    BitVecNot(&result_bv, &bv1);
    result = result && (result_bv.length == 0);
    
    // Test reverse even length
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, false);
    
    // Test with single bit operands
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    // Test with single bit operands
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    BitVecPush(&bv2, false);
    
    // Test NOT on large bitvector
    BitVecClear(&bv1);
    for (int i = 0; i < 100; i++) {
    BitVecPush(&bv1, i % 3 == 0);
    
    // Test shifting by exactly length (should clear everything)
    BitVecClear(&bv);
    for (int i = 0; i < 8; i++) {
    BitVecPush(&bv, true);
    
    // Test shifting by more than length
    BitVecClear(&bv);
    for (int i = 0; i < 5; i++) {
    BitVecPush(&bv, true);
    
    // Test boundary conditions - shift by length-1
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, true);
    
    // Test rotate with odd length
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, false);
    
    // Test A AND 0 = 0
    BitVecClear(&bv2);
    for (int i = 0; i < 16; i++) {
    BitVecPush(&bv2, false);
    
    // Test A OR 1 = 1
    BitVecClear(&bv2);
    for (int i = 0; i < 16; i++) {
    BitVecPush(&bv2, true);
    
    // Test shift on large data
    BitVecClear(&result);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&result, i % 2 == 0);
    
    // Test large conversions
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test foreach on large data
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test foreach idx ordering
    BitVecClear(&bv);
    for (int i = 0; i < 10; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test reverse ordering
    BitVecClear(&bv);
    BitVecPush(&bv, true);                          // idx 0
    BitVecPush(&bv, false);                         // idx 1
    
    // Test with complex random-like pattern
    BitVecClear(&large_bv);
    
    // Pattern: 1111000011100010000111 (variable length runs)
    
    // Pattern 2: Single bit pattern
    BitVecClear(&pattern);
    BitVecPush(&pattern, true);
    index  = BitVecFindPattern(&source, &pattern);
    
    // Pattern 3: Non-existent pattern
    BitVecClear(&pattern);
    BitVecPush(&pattern, false);
    BitVecPush(&pattern, false);
    
    // Pattern 4: Pattern at the end
    BitVecClear(&pattern);
    BitVecPush(&pattern, true);
    BitVecPush(&pattern, false);
    
    // Test with pattern that occurs only once
    BitVecClear(&source);
    BitVecClear(&pattern);
    // Test with pattern that occurs only once
    BitVecClear(&source);
    BitVecClear(&pattern);
    
    // Source: 110011
    
    // Test with non-overlapping pattern
    BitVecClear(&source);
    BitVecClear(&pattern);
    // Test with non-overlapping pattern
    BitVecClear(&source);
    BitVecClear(&pattern);
    
    // Source: 110110110
    
    // Test pattern longer than source
    BitVecClear(&pattern);
    for (int i = 0; i < 5; i++) {
    BitVecPush(&pattern, true);
    
    // Test empty source
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&pattern, true);
    // Test empty source
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&pattern, true);
    index  = BitVecFindPattern(&source, &pattern);
    
    // Test exact match (pattern same as source)
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    // Test exact match (pattern same as source)
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    BitVecPush(&source, false);
    
    // Test single bit source and pattern
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    // Test single bit source and pattern
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    BitVecPush(&pattern, true);
    // Test BitVecFindAllPattern edge cases
    size results[1];
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    size results[1];
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    BitVecPush(&pattern, true);
    
    // Test non-matching prefix: 101
    BitVecClear(&prefix);
    BitVecPush(&prefix, true);
    BitVecPush(&prefix, false);
    
    // Test prefix longer than source
    BitVecClear(&source);
    BitVecPush(&prefix, true);
    BitVecPush(&prefix, false);
    
    // Test equal length
    BitVecClear(&source);
    BitVecClear(&prefix);
    BitVecPush(&source, true);
    // Test equal length
    BitVecClear(&source);
    BitVecClear(&prefix);
    BitVecPush(&source, true);
    BitVecPush(&source, false);
    
    // Test non-matching suffix: 110
    BitVecClear(&suffix);
    BitVecPush(&suffix, true);
    BitVecPush(&suffix, true);
    
    // Test suffix longer than source
    BitVecClear(&source);
    BitVecPush(&suffix, true);
    BitVecPush(&suffix, false);
    
    // Test non-existing pattern: 000
    BitVecClear(&pattern);
    BitVecPush(&pattern, false);
    BitVecPush(&pattern, false);
    
    // Test pattern: 010 (should find 3 occurrences at 1, 3, 5)
    BitVecClear(&pattern);
    BitVecPush(&pattern, false);
    BitVecPush(&pattern, true);
    
    // Test completely different bitvectors
    BitVecClear(&bv2);
    BitVecPush(&bv2, false);
    BitVecPush(&bv2, true);
    
    // Test partially different bitvectors
    BitVecClear(&bv2);
    BitVecPush(&bv2, true); // Same
    BitVecPush(&bv2, true); // Different
    
    // Test one empty, one non-empty
    BitVecClear(&bv2);
    distance = BitVecHammingDistance(&bv1, &bv2);
    result   = result && (distance == 2); // Length of bv1
    
    // Test no overlap
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    // Test no overlap
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    BitVecPush(&bv1, false);
    
    // Test partial overlap
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    // Test partial overlap
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    BitVecPush(&bv1, true);
    
    // Test orthogonal vectors
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    // Test orthogonal vectors
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    BitVecPush(&bv1, false);
    
    // Test one zero vector
    BitVecClear(&bv2);
    BitVecPush(&bv2, true);
    BitVecPush(&bv2, false);
    
    // Test no overlap
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    // Test no overlap
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    BitVecPush(&bv1, true);
    BitVecPush(&bv1, false);
    
    // Test single substitution
    BitVecClear(&bv2);
    BitVecPush(&bv2, true);
    BitVecPush(&bv2, true); // Changed from false
    
    // Test insertion
    BitVecClear(&bv2);
    BitVecPush(&bv2, true);
    BitVecPush(&bv2, false);
    
    // Test perfect anti-correlation
    BitVecClear(&bv2);
    BitVecPush(&bv2, false);
    BitVecPush(&bv2, true);
    
    // Test minimum entropy (all same)
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, true);
    
    // Test perfect mismatch
    BitVecClear(&bv2);
    BitVecPush(&bv2, false);
    BitVecPush(&bv2, true);
    
    // Pattern 2: Single bit pattern
    BitVecClear(&pattern);
    BitVecPush(&pattern, true);
    index  = BitVecFindPattern(&source, &pattern);
    
    // Pattern 3: Non-existent pattern
    BitVecClear(&pattern);
    BitVecPush(&pattern, false);
    BitVecPush(&pattern, false);
    
    // Pattern 4: Pattern at the end
    BitVecClear(&pattern);
    BitVecPush(&pattern, true);
    BitVecPush(&pattern, false);
    
    // Test with pattern that occurs only once
    BitVecClear(&source);
    BitVecClear(&pattern);
    // Test with pattern that occurs only once
    BitVecClear(&source);
    BitVecClear(&pattern);
    
    // Source: 110011
    
    // Test with non-overlapping pattern
    BitVecClear(&source);
    BitVecClear(&pattern);
    // Test with non-overlapping pattern
    BitVecClear(&source);
    BitVecClear(&pattern);
    
    // Source: 110110110
    
    // Test pattern longer than source
    BitVecClear(&pattern);
    for (int i = 0; i < 5; i++) {
    BitVecPush(&pattern, true);
    
    // Test empty source
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&pattern, true);
    // Test empty source
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&pattern, true);
    index  = BitVecFindPattern(&source, &pattern);
    
    // Test exact match (pattern same as source)
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    // Test exact match (pattern same as source)
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    BitVecPush(&source, false);
    
    // Test single bit source and pattern
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    // Test single bit source and pattern
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    BitVecPush(&pattern, true);
    // Test BitVecFindAllPattern edge cases
    size results[1];
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    size results[1];
    BitVecClear(&source);
    BitVecClear(&pattern);
    BitVecPush(&source, true);
    BitVecPush(&pattern, true);
    
    // Test non-matching prefix: 101
    BitVecClear(&prefix);
    BitVecPush(&prefix, true);
    BitVecPush(&prefix, false);
    
    // Test prefix longer than source
    BitVecClear(&source);
    BitVecPush(&prefix, true);
    BitVecPush(&prefix, false);
    
    // Test equal length
    BitVecClear(&source);
    BitVecClear(&prefix);
    BitVecPush(&source, true);
    // Test equal length
    BitVecClear(&source);
    BitVecClear(&prefix);
    BitVecPush(&source, true);
    BitVecPush(&source, false);
    
    // Test non-matching suffix: 110
    BitVecClear(&suffix);
    BitVecPush(&suffix, true);
    BitVecPush(&suffix, true);
    
    // Test suffix longer than source
    BitVecClear(&source);
    BitVecPush(&suffix, true);
    BitVecPush(&suffix, false);
    
    // Test non-existing pattern: 000
    BitVecClear(&pattern);
    BitVecPush(&pattern, false);
    BitVecPush(&pattern, false);
    
    // Test pattern: 010 (should find 3 occurrences at 1, 3, 5)
    BitVecClear(&pattern);
    BitVecPush(&pattern, false);
    BitVecPush(&pattern, true);
    
    // Clear and check empty
    BitVecClear(&bv);
    result = result && BitVecEmpty(&bv);
    result = result && (BitVecLen(&bv) == 0);
    
    // Test with all ones
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, true);
    
    // Test with large data set
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, i % 3 == 0);
    result = result && (BitVecCountZeros(&bv) == 0);
    
    BitVecClear(&bv);
    BitVecPush(&bv, false);
    result = result && (BitVecCountOnes(&bv) == 0);
    
    // Test count with large uniform data
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, true);
    
    // Test with exactly power-of-2 sizes
    BitVecClear(&bv);
    for (int i = 0; i < 64; i++) { // Exactly 64 bits
    BitVecPush(&bv, true);
    
    // Test checkerboard pattern
    BitVecClear(&bv);
    for (int i = 0; i < 100; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test Fibonacci-like pattern (each bit is XOR of previous two)
    BitVecClear(&bv);
    BitVecPush(&bv, true); // F(0) = 1
    BitVecPush(&bv, true); // F(1) = 1
    
    // Test with all same values
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, true);
    
    // Test with all false bits
    BitVecClear(&bv);
    BitVecPush(&bv, false);
    BitVecPush(&bv, false);
    
    // Test with mixed bits
    BitVecClear(&bv);
    BitVecPush(&bv, true);
    BitVecPush(&bv, false);
    
    // Test with all same values
    BitVecClear(&bv);
    for (int i = 0; i < 10; i++) {
    BitVecPush(&bv, true);
    
    // Test alternating pattern
    BitVecClear(&bv);
    for (int i = 0; i < 10; i++) {
    BitVecPush(&bv, i % 2 == 0);
    
    // Test with large bitvector
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, i == 500 || i == 999); // Only indices 500 and 999 are true
    
    // Test large bitvector with specific patterns
    BitVecClear(&bv);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv, true); // All true
    
    // Test large runs
    BitVecClear(&bv);
    for (int i = 0; i < 10000; i++) {
    BitVecPush(&bv, true);
    
    // Test first greater than second
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    // Test first greater than second
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    
    BitVecPush(&bv1, true);
    
    // Test equal bitvectors
    BitVecClear(&bv2);
    BitVecPush(&bv2, true);
    BitVecPush(&bv2, false);
    
    // Test equal values
    BitVecClear(&bv2);
    BitVecPush(&bv2, true);
    BitVecPush(&bv2, false);
    
    // Test equal weights
    BitVecClear(&bv2);
    BitVecPush(&bv2, true);
    BitVecPush(&bv2, true);
    
    // Test equal sets (should be subset)
    BitVecClear(&superset);
    BitVecPush(&superset, true);
    BitVecPush(&superset, false);
    
    // Test two positives
    BitVecClear(&bv2);
    // bv2: 001 (positive 1)
    BitVecPush(&bv2, true);
    
    // Test equal sets (should be superset)
    BitVecClear(&superset);
    BitVecPush(&superset, true);
    BitVecPush(&superset, false);
    
    // Test non-overlapping bitvectors
    BitVecClear(&bv2);
    // bv2: 0101 (complement of bv1)
    BitVecPush(&bv2, false);
    
    // Test with empty bitvectors
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    result = result && BitVecDisjoint(&bv1, &bv2);
    // Test with empty bitvectors
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    result = result && BitVecDisjoint(&bv1, &bv2);
    result = result && !BitVecOverlaps(&bv1, &bv2);
    
    // Test all zeros
    BitVecClear(&bv);
    for (int i = 0; i < 5; i++) {
    BitVecPush(&bv, false);
    
    // Test all ones
    BitVecClear(&bv);
    for (int i = 0; i < 5; i++) {
    BitVecPush(&bv, true);
    
    // Test large identical bitvecs
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    for (int i = 0; i < 1000; i++) {
    // Test large identical bitvecs
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    for (int i = 0; i < 1000; i++) {
    bool bit = i % 3 == 0;
    
    // Test subset operations on empty sets
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    result = result && BitVecIsSubset(&bv1, &bv2); // Empty is subset of empty
    // Test subset operations on empty sets
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    result = result && BitVecIsSubset(&bv1, &bv2); // Empty is subset of empty
    
    // Test large sets
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    for (int i = 0; i < 1000; i++) {
    // Test large sets
    BitVecClear(&bv1);
    BitVecClear(&bv2);
    for (int i = 0; i < 1000; i++) {
    BitVecPush(&bv1, i % 2 == 0);

Share :

Related Posts

BitVecReplaceAll

BitVecReplaceAll Description Replace all occurrences of old pattern with new pattern.

Read More

BitVecMatches

BitVecMatches Description Match bitvector against pattern with wildcards. Wildcards allow flexible pattern matching where some positions can be “any bit”.

Read More

BitVecDeinit

BitVecDeinit Description Deinitialize bitvector and free all allocated memory. After calling this, the bitvector should not be used unless re-initialized.

Read More