VecInsertFastR

Table of Contents

VecInsertFastR

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.

Parameters

NameDirectionDescription
vin,outVector to insert item into
lvalinr-value to be inserted
idxinIndex to insert item at.

Success

return

Failure

Does not return

Usage example (Cross-references)

    /// idx[in]   : Index to insert item at.
    ///
    #define VecInsertFast(v, lval, idx) VecInsertFastR((v), (lval), (idx))
    
    ///
    
    // Test R-value fast insert
    VecInsertFastR(&vec, LVAL(60), 1);
    
    // Check that the element was inserted
    // Use a temporary variable to avoid r-value issues
    int temp = 99;
    VecInsertFastR(&vec, temp, 2);
    
    // Check vector length
    // Try inserting just one element first with fast insert
    int single_val = 42;
    VecInsertFastR(&vec2, single_val, 2);
    
    result = result && (vec2.length == 6);

Share :