BitVecInsertRange

Table of Contents

BitVecInsertRange

Description

Insert multiple bits of the same value at a specific position. All existing bits at and after the position are shifted right.

Parameters

NameDirectionDescription
bvinBitvector to insert into
idxinPosition to insert at (0-based)
countinNumber of bits to insert
valueinValue for all inserted bits (true or false)

Usage example (from documentation)

  BitVecInsertRange(&flags, 2, 5, true);  // Insert 5 true bits at position 2

Usage example (Cross-references)

    }
    
    void BitVecInsertRange(BitVec *bv, u64 idx, u64 count, bool value) {
    ValidateBitVec(bv);
    if (idx > bv->length) {
    // Test BitVecInsertRange function
    bool test_bitvec_insert_range(void) {
    printf("Testing BitVecInsertRange\n");
    
    BitVec bv = BitVecInit();
    
    // Insert range of true bits
    BitVecInsertRange(&bv, 1, 3, true);
    
    // Check result: false, true, true, true, false
    // Edge case tests
    bool test_bitvec_insert_range_edge_cases(void) {
    printf("Testing BitVecInsertRange edge cases\n");
    
    BitVec bv     = BitVecInit();
    
    // Test inserting 0 bits (should be no-op)
    BitVecInsertRange(&bv, 0, 0, true);
    result = result && (bv.length == 0);
    // Test inserting at end
    BitVecPush(&bv, true);
    BitVecInsertRange(&bv, 1, 2, false);
    result = result && (bv.length == 3);
    result = result && (BitVecGet(&bv, 1) == false);
    // Test large range insertion
    BitVecClear(&bv);
    BitVecInsertRange(&bv, 0, 1000, true);
    result = result && (bv.length == 1000);
    result = result && (BitVecGet(&bv, 0) == true);
    
    // Test NULL bitvec pointer - should abort
    BitVecInsertRange(NULL, 0, 1, true);
    
    return false;
    
    // Test inserting beyond capacity limit - should abort
    BitVecInsertRange(&bv, SIZE_MAX, 1, true);
    
    BitVecDeinit(&bv);

Share :

Related Posts

BitVecAll

BitVecAll Description Check if all bits in bitvector match the given value.

Read More

BitVecPrefixMatch

BitVecPrefixMatch Description Match bitvector against an array of prefix patterns. Returns the index of the first matching prefix.

Read More

BitVecCompareRange

BitVecCompareRange Description Compare ranges of two bitvectors lexicographically.

Read More