BitVecRemove

Table of Contents

BitVecRemove

Description

Remove a bit at given index from bitvector. Shifts all bits after the index to the left.

Parameters

NameDirectionDescription
bvinBitvector to remove bit from
idxinIndex of bit to remove (0-based)

Usage example (from documentation)

  bool removed_bit = BitVecRemove(&flags, 5);

Usage example (Cross-references)

    }
    
    bool BitVecRemove(BitVec *bv, u64 idx) {
    ValidateBitVec(bv);
    if (idx >= bv->length) {
    u64 pos = BitVecFind(bv, value);
    if (pos != SIZE_MAX) {
    BitVecRemove(bv, pos);
    return true;
    }
    u64 pos = BitVecFindLast(bv, value);
    if (pos != SIZE_MAX) {
    BitVecRemove(bv, pos);
    return true;
    }
    // Test BitVecRemove single bit function
    bool test_bitvec_remove_single(void) {
    printf("Testing BitVecRemove (single bit)\n");
    
    BitVec bv = BitVecInit();
    
    // Remove bit at index 2 (middle true)
    bool removed = BitVecRemove(&bv, 2);
    
    // Check result: true, false, false, true
    
    // Remove bit at index 0 (first bit)
    removed = BitVecRemove(&bv, 0);
    result  = result && (removed == true) && (bv.length == 3);
    result  = result && (BitVecGet(&bv, 0) == false);
    
    bool test_bitvec_remove_single_edge_cases(void) {
    printf("Testing BitVecRemove edge cases\n");
    
    BitVec bv     = BitVecInit();
    // Test remove last element
    BitVecPush(&bv, true);
    bool removed = BitVecRemove(&bv, 0);
    result       = result && (removed == true) && (bv.length == 0);
    
    // Remove middle element
    removed = BitVecRemove(&bv, 500);
    result  = result && (removed == (500 % 3 == 0)); // Should return the value of the removed bit
    result  = result && (bv.length == 999);
    
    // Test remove from empty bitvec - should abort
    BitVecRemove(&bv, 0);
    
    BitVecDeinit(&bv);

Share :

Related Posts

BitVecPop

BitVecPop Description Pop the last bit from bitvector. Returns the value of the removed bit.

Read More

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

BitVecRemoveLast

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

Read More