BitVecInsertMultiple

Table of Contents

BitVecInsertMultiple

Description

Insert all bits from another bitvector 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)
otherinBitvector whose bits to insert

Usage example (from documentation)

  BitVecInsertMultiple(&flags, 2, &other_flags);

Usage example (Cross-references)

    }
    
    void BitVecInsertMultiple(BitVec *bv, u64 idx, BitVec *other) {
    ValidateBitVec(bv);
    ValidateBitVec(other);
    // Test BitVecInsertMultiple function
    bool test_bitvec_insert_multiple(void) {
    WriteFmt("Testing BitVecInsertMultiple\n");
    
    BitVec bv     = BitVecInit();
    
    // Insert multiple bits from source
    BitVecInsertMultiple(&bv, 1, &source);
    
    // Check result: true, true, true, true, false
    
    bool test_bitvec_insert_multiple_edge_cases(void) {
    WriteFmt("Testing BitVecInsertMultiple edge cases\n");
    
    BitVec bv     = BitVecInit();
    
    // Test inserting empty bitvec
    BitVecInsertMultiple(&bv, 0, &empty);
    result = result && (bv.length == 0);
    // Test inserting single bit bitvec
    BitVecPush(&source, true);
    BitVecInsertMultiple(&bv, 0, &source);
    result = result && (bv.length == 1) && (BitVecGet(&bv, 0) == true);
    BitVecPush(&source, false);
    }
    BitVecInsertMultiple(&bv, 1, &source);
    result = result && (bv.length == 501);
    result = result && (BitVecGet(&bv, 1) == false);

Share :

Related Posts

BitVecPrefixMatch

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

Read More

BitVecRemoveRange

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

Read More

BitVecAll

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

Read More