Skip to content
BitVecRemoveFirst

BitVecRemoveFirst

Description

Remove the first occurrence of a specific bit value.

Parameters

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

Usage example (from documentation)

  bool found = BitVecRemoveFirst(&flags, true);

Success

Returns true. The first bit equal to value has been removed; bitvector length shrinks by one; subsequent bits have shifted left by one.

Failure

Returns false when no bit equal to value was found. The bitvector is unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool BitVecRemoveFirst(BitVec *bv, bool value) {
        ValidateBitVec(bv);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecRemoveFirst\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // 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) && (BitVecLen(&bv) == 3);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecRemoveFirst/Last edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test remove from empty bitvec
        bool found = BitVecRemoveFirst(&bv, true);
        result     = result && (found == false) && (BitVecLen(&bv) == 0);
        BitVecPush(&bv, true);
        BitVecPush(&bv, true);
        found  = BitVecRemoveFirst(&bv, false);
        result = result && (found == false) && (BitVecLen(&bv) == 2);
        BitVecClear(&bv);
        BitVecPush(&bv, false);
        found  = BitVecRemoveFirst(&bv, false);
        result = result && (found == true) && (BitVecLen(&bv) == 0);
            BitVecPush(&bv, true);
        }
        found  = BitVecRemoveFirst(&bv, true);
        result = result && (found == true) && (BitVecLen(&bv) == 999);
Last updated on