BitVecRemoveFirst

Table of Contents

BitVecRemoveFirst

Description

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

Parameters

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

Usage example (from documentation)

  bool found = BitVecRemoveFirst(&flags, true);

Usage example (Cross-references)

    }
    
    bool BitVecRemoveFirst(BitVec *bv, bool value) {
    ValidateBitVec(bv);
    // Test BitVecRemoveFirst function
    bool test_bitvec_remove_first(void) {
    WriteFmt("Testing BitVecRemoveFirst\n");
    
    BitVec bv = BitVecInit();
    
    // Remove first occurrence of false
    bool found = BitVecRemoveFirst(&bv, false);
    
    // Check result: true, true, false, true (removed first false at index 1)
    // Try to remove first occurrence of a value that doesn't exist (after removal)
    // Actually, false still exists at index 2, so let's remove all falses first
    BitVecRemoveFirst(&bv, false); // Remove the remaining false
    
    // Now try to remove false from a bitvector with only trues
    
    // Now try to remove false from a bitvector with only trues
    found  = BitVecRemoveFirst(&bv, false);
    result = result && (found == false) && (bv.length == 3);
    
    bool test_bitvec_remove_first_last_edge_cases(void) {
    WriteFmt("Testing BitVecRemoveFirst/Last edge cases\n");
    
    BitVec bv     = BitVecInit();
    
    // Test remove from empty bitvec
    bool found = BitVecRemoveFirst(&bv, true);
    result     = result && (found == false) && (bv.length == 0);
    BitVecPush(&bv, true);
    BitVecPush(&bv, true);
    found  = BitVecRemoveFirst(&bv, false);
    result = result && (found == false) && (bv.length == 2);
    BitVecClear(&bv);
    BitVecPush(&bv, false);
    found  = BitVecRemoveFirst(&bv, false);
    result = result && (found == true) && (bv.length == 0);
    BitVecPush(&bv, true);
    }
    found  = BitVecRemoveFirst(&bv, true);
    result = result && (found == true) && (bv.length == 999);

Share :

Related Posts

BitVecOr

BitVecOr Description Perform bitwise OR operation between two bitvectors. Result is stored in the first bitvector.

Read More

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

BitVecNot

BitVecNot Description Perform bitwise NOT operation on a bitvector. Result is stored in the first bitvector.

Read More