Skip to content
BitVecRemoveFirst

BitVecRemoveFirst

BitVecRemoveFirst

Description

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

Parameters

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

Usage example (from documentation)

  bool found = BitVecRemoveFirst(&flags, true);

Returns

true if bit was found and removed, false if not found

Usage example (Cross-references)

Usage examples (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);
Last updated on