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

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

BitVecBestAlignment

BitVecBestAlignment Description Find best overlapping alignment between two bitvectors. Returns the offset that gives the best alignment score.

Read More

BitVecAlignmentScore

BitVecAlignmentScore Description Calculate alignment score between two bitvectors. Used in bioinformatics-style sequence alignment with match/mismatch scoring.

Read More