BitVecRemoveRange

Table of Contents

BitVecRemoveRange

Description

Remove multiple consecutive bits starting at a specific position. All bits after the removed range are shifted left.

Parameters

NameDirectionDescription
bvinBitvector to remove from
idxinStarting position (0-based)
countinNumber of bits to remove

Usage example (from documentation)

  BitVecRemoveRange(&flags, 2, 3);  // Remove 3 bits starting at position 2

Usage example (Cross-references)

    }
    
    void BitVecRemoveRange(BitVec *bv, u64 idx, u64 count) {
    ValidateBitVec(bv);
    if (idx >= bv->length) {
    
    // Remove old pattern
    BitVecRemoveRange(bv, pos, old_pattern->length);
    
    // Insert new pattern
    
    // Remove old pattern
    BitVecRemoveRange(bv, match_pos, old_pattern->length);
    
    // Insert new pattern
    // Test BitVecRemoveRange function
    bool test_bitvec_remove_range(void) {
    WriteFmt("Testing BitVecRemoveRange\n");
    
    BitVec bv = BitVecInit();
    
    // Remove range from index 1 to 3 (3 bits)
    BitVecRemoveRange(&bv, 1, 3);
    
    // Check result: true, false, true (removed false, true, true)
    
    bool test_bitvec_remove_range_edge_cases(void) {
    WriteFmt("Testing BitVecRemoveRange edge cases\n");
    
    BitVec bv     = BitVecInit();
    // Test remove 0 elements (should be no-op)
    BitVecPush(&bv, true);
    BitVecRemoveRange(&bv, 0, 0);
    result = result && (bv.length == 1);
    BitVecPush(&bv, i % 2 == 0);
    }
    BitVecRemoveRange(&bv, 0, 10);
    result = result && (bv.length == 0);
    BitVecPush(&bv, i % 2 == 0);
    }
    BitVecRemoveRange(&bv, 1, 5);        // Remove 5 elements starting at index 1
    result = result && (bv.length == 5); // Should have 5 elements left
    
    // Test NULL bitvec pointer - should abort
    BitVecRemoveRange(NULL, 0, 1);
    
    return false;
    
    // Test removing beyond capacity limit - should abort
    BitVecRemoveRange(&bv, SIZE_MAX, 1);
    
    BitVecDeinit(&bv);
    
    // Test remove range from empty bitvec - should abort
    BitVecRemoveRange(&bv, 0, 1);
    
    BitVecDeinit(&bv);

Share :

Related Posts

BitVecCosineSimilarity

BitVecCosineSimilarity Description Calculate cosine similarity between two bitvectors. Treats bitvectors as binary vectors and computes cosine of angle between them.

Read More

BitVecDotProduct

BitVecDotProduct Description Calculate dot product of two bitvectors. Dot product is the count of positions where both bits are 1.

Read More

BitVecInsertMultiple

BitVecInsertMultiple Description Insert all bits from another bitvector at a specific position. All existing bits at and after the position are shifted right.

Read More