Skip to content
BitVecInsertRange

BitVecInsertRange

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

Name Direction Description
bv in Bitvector to insert into
idx in Position to insert at (0-based)
count in Number of bits to insert
value in Value 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)

Usage examples (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) {
        WriteFmt("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) {
        WriteFmt("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);
Last updated on