Skip to content
BitVecRemoveAll

BitVecRemoveAll

BitVecRemoveAll

Description

Remove all occurrences of a specific bit value. Returns the number of bits that were removed.

Parameters

Name Direction Description
bv in Bitvector to remove from
value in Bit value to remove (true or false)

Usage example (from documentation)

  u64 removed = BitVecRemoveAll(&flags, true);

Returns

Number of bits removed

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    u64 BitVecRemoveAll(BitVec *bv, bool value) {
        ValidateBitVec(bv);
    // Test BitVecRemoveAll function
    bool test_bitvec_remove_all(void) {
        WriteFmt("Testing BitVecRemoveAll\n");
    
        BitVec bv = BitVecInit();
    
        // Remove all false bits
        u64 removed_count = BitVecRemoveAll(&bv, false);
    
        // Check result: true, true, true (all false bits removed)
    
        // Try to remove all false bits again (should return 0)
        removed_count = BitVecRemoveAll(&bv, false);
        result        = result && (removed_count == 0) && (bv.length == 3);
    
        // Remove all true bits
        removed_count = BitVecRemoveAll(&bv, true);
        result        = result && (removed_count == 3) && (bv.length == 0);
    
    bool test_bitvec_remove_all_edge_cases(void) {
        WriteFmt("Testing BitVecRemoveAll edge cases\n");
    
        BitVec bv     = BitVecInit();
    
        // Test remove all from empty bitvec
        u64 count = BitVecRemoveAll(&bv, true);
        result    = result && (count == 0) && (bv.length == 0);
        BitVecPush(&bv, true);
        BitVecPush(&bv, true);
        count  = BitVecRemoveAll(&bv, false);
        result = result && (count == 0) && (bv.length == 2);
            BitVecPush(&bv, true);
        }
        count  = BitVecRemoveAll(&bv, true);
        result = result && (count == 100) && (bv.length == 0);
            BitVecPush(&bv, i % 2 == 0);
        }
        count  = BitVecRemoveAll(&bv, false); // Remove odds
        result = result && (count == 500) && (bv.length == 500);
Last updated on