Skip to content
VecInsertRangeFastR

VecInsertRangeFastR

Description

Insert a range using fast (order-not-preserving) placement. R-value form.

Success

Returns true. Same state effects as VecInsertRangeFastL minus the source-zeroing step; the source range is left untouched.

Failure

Returns false on allocation failure. The vector is unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
    /// TAGS: Vec, PushFront, Range, RValue, Fast, Unordered
    ///
    #define VecPushFrontArrFastR(v, arr, count) VecInsertRangeFastR((v), (arr), 0, (count))
    
    ///
    #define VecMustInsertRangeFastR(v, varr, idx, count)                                                                   \
        do {                                                                                                               \
            if (!VecInsertRangeFastR((v), (varr), (idx), (count))) {                                                       \
                LOG_FATAL("VecMustInsertRangeFastR failed");                                                               \
            }                                                                                                              \
    #define StrInsertManyFast(...) OVERLOAD(StrInsertManyFast, __VA_ARGS__)
    #define StrInsertManyFast_3(str, zstr, idx)                                                                        \
        _Generic((zstr), Zstr: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrInsertManyFast_4(str, cstr, cstr_len, idx)                                                              \
        _Generic((cstr), Zstr: VecInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)))
        _Generic((zstr), Zstr: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrInsertManyFast_4(str, cstr, cstr_len, idx)                                                              \
        _Generic((cstr), Zstr: VecInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)))
    
    ///
    /// TAGS: Str, Insert, Range, RValue, Fast, Unordered
    ///
    #define StrInsertRangeFastR(str, varr, idx, count) VecInsertRangeFastR((str), (varr), (idx), (count))
    
    ///
                        values[i] = (i32)extract_u32(data, offset, data_size);
                    }
                    VecInsertRangeFastR(vec, values, idx, count);
                }
                break;
    
        // Use VecInsertRangeFastR with a small array
        VecInsertRangeFastR(&vec2, small_arr, 1, 2);
    
        // Check vector length
        size new_count   = sizeof(new_items) / sizeof(new_items[0]);
    
        bool result = VecInsertRangeFastR(&vec, new_items, idx, new_count);
        result      = result && (VecLen(&vec) == orig_count + new_count);
            {.value = 1, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, src, 0, (size)-1);
    
        bool result = (ok == false) && (VecLen(&vec) == 0);
    
        int  add[8] = {100, 101, 102, 103, 104, 105, 106, 107};
        bool ok     = VecInsertRangeFastR(&vec, add, VecLen(&vec), 8);
    
        // Capacity contract: holding 16 live elements requires the grow to have
        // length 5 + count 5 == capacity 10: the equality boundary.
        int  add[5] = {100, 101, 102, 103, 104};
        bool ok     = VecInsertRangeFastR(&vec, add, VecLen(&vec), 5);
    
        // Real code reserves past the old capacity (10 -> 16). The `>` mutant skips
    
        int  add[8] = {10, 20, 30, 40, 50, 60, 70, 80};
        bool ok     = VecInsertRangeFastR(&vec, add, 0, 8);
    
        // Holding 8 elements requires growth from capacity 0; the mutant's
    
        int  add[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        bool ok      = VecInsertRangeFastR(&vec, add, 0, 10);
    
        // A truthy replacement skips the realloc (capacity stays 0); a zero
            {.value = 200, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 1, 2);
    
        bool result = ok && (VecLen(&vec) == 6);
        }
    
        bool ok = VecInsertRangeFastR(&vec, VecBegin(&ins), 0, N);
    
        bool result = ok && (VecLen(&vec) == 2 * N);
            {.value = 200, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 2, 2);
    
        bool result = ok && (VecLen(&vec) == 6);
            {.value = 200, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 2, 2);
    
        bool result = ok && (VecLen(&vec) == 6);
            {.value = 300, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 1, 3);
    
        bool result = ok && (VecLen(&vec) == 5);
            {.value = 300, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 2, 3);
    
        bool result = (ok == false) && (g_deinit_count == 0) && (VecLen(&vec) == 4);
            {.value = 300, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 2, 3);
    
        bool result = (ok == false) && (g_deinit_count == 1);
            {.value = 200, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 2, 2);
    
        bool result = (ok == false) && (g_deinit_count == 0);
            {.value = 400, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 2, 4);
    
        bool result = (ok == false) && (g_deinit_count == 2);
            {.value = 400, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 2, 4);
    
        bool result = (ok == false) && (g_deinit_count == 2);
            {.value = 400, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 2, 4);
    
        bool result = (ok == false) && (g_deinit_count == 2);
            {.value = 200, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 2, 2);
    
        bool result = (ok == false) && (g_deinit_count == 1) && deinit_log_contains(100);
            {.value = 200, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 1, 2);
    
        bool result = (ok == false) && (VecLen(&vec) == 5);
            {.value = 200, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 1, 2);
    
        bool result = (ok == false) && (VecLen(&vec) == 5);
            {.value = 300, .live = false}
        };
        bool ok = VecInsertRangeFastR(&vec, add, 1, 3);
    
        bool result = (ok == false) && (VecLen(&vec) == 6);
        g_fail_at    = 1;
        Elem add[2]  = {{.value = 7000}, {.value = 8000}};
        bool ok      = VecInsertRangeFastR(&vec, add, 0, 2);
    
        bool result = (ok == false) && (VecLen(&vec) == length_before);
Last updated on