Skip to content
VecInsertFastL

VecInsertFastL

VecInsertFastL

Description

Quickly insert item into vector. Ordering of elements is not guaranteed to be preserved. This call makes significant difference only for sufficiently large vectors and when idx is quite less than (v)->length.

Insertion time is guaranteed to be constant for same data types.

Usage is exactly same as VecInsert, just the internal implementation is different.

If copy_init is set, then vector will create it’s own copy of items.
Ownership of item is transferred to vector if no copy_init method is set. This is to prevent multiple ownership of same object, once inserted into vector. Object won’t be usable after this call if copy_init is not set.

Parameters

Name Direction Description
v in,out Vector to insert item into
lval in l-value to be inserted
idx in Index to insert item at.

Success

return

Failure

Does not return

Usage example (Cross-references)

Usage examples (Cross-references)
    // Test VecInsertFastL memset behavior with complex structures
    bool test_lvalue_memset_fast_insert(void) {
        WriteFmt("Testing VecInsertFastL memset with complex structures\n");
        bool result = true;
        int         values1[] = {10, 20, 30};
        ComplexItem item1     = CreateComplexItem("Fast Item 1", values1, 3);
        VecInsertFastL(&vec, item1, 0);
    
        // Check that the item was memset to 0
        int         values2[] = {40, 50, 60};
        ComplexItem item2     = CreateComplexItem("Fast Item 2", values2, 3);
        VecInsertFastL(&vec, item2, 2);
    
        // Check that the item was memset to 0
        int         values3[] = {70, 80, 90};
        ComplexItem item3     = CreateComplexItem("Fast Item 3", values3, 3);
        VecInsertFastL(&vec, item3, vec.length);
    
        // Check that the item was memset to 0
        // Test L-value fast insert
        int fast_value = 80;
        VecInsertFastL(&vec, fast_value, 3);
    
        // Check that the element was inserted
        // Test VecInsertFastL
        int val4 = 70;
        VecInsertFastL(&vec, val4, 2);
        result = result && (val4 == 0); // Should be memset to 0
Last updated on