Skip to content
BitVecInsertMultiple

BitVecInsertMultiple

Description

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

Parameters

Name Direction Description
bv in,out Bitvector to insert into.
idx in Position to insert at (0-based), in [0, length].
other in Bitvector whose bits to insert.

Usage example (from documentation)

  BitVecInsertMultiple(&flags, 2, &other_flags);

Success

Returns true. Bitvector length grows by other->length; the range [idx, idx + other->length) mirrors the bits of other in order; previous bits at and after idx have shifted right by other->length. other is untouched.

Failure

Returns false on allocation failure when capacity must grow. The bitvector is unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool BitVecInsertMultiple(BitVec *bv, u64 idx, BitVec *other) {
        ValidateBitVec(bv);
        ValidateBitVec(other);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecInsertMultiple\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Insert multiple bits from source
        BitVecInsertMultiple(&bv, 1, &source);
    
        // Check result: true, true, true, true, false
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecInsertMultiple edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test inserting empty bitvec
        BitVecInsertMultiple(&bv, 0, &empty);
        result = result && (BitVecLen(&bv) == 0);
        // Test inserting single bit bitvec
        BitVecPush(&source, true);
        BitVecInsertMultiple(&bv, 0, &source);
        result = result && (BitVecLen(&bv) == 1) && (BitVecGet(&bv, 0) == true);
            BitVecPush(&source, false);
        }
        BitVecInsertMultiple(&bv, 1, &source);
        result = result && (BitVecLen(&bv) == 501);
        result = result && (BitVecGet(&bv, 1) == false);
    #define BitVecMustInsertMultiple(bv, idx, other)                                                                       \
        do {                                                                                                               \
            if (!BitVecInsertMultiple((bv), (idx), (other))) {                                                             \
                LOG_FATAL("BitVecMustInsertMultiple failed");                                                              \
            }                                                                                                              \
Last updated on