BitVecRemoveAll

Table of Contents

BitVecRemoveAll

Description

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

Parameters

NameDirectionDescription
bvinBitvector to remove from
valueinBit value to remove (true or false)

Usage example (from documentation)

  u64 removed = BitVecRemoveAll(&flags, true);

Usage example (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);

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

BitVecShiftRight

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