VecInsertFastL
Description
Insert a single element using fast (order-not-preserving) placement: the element previously occupying idx is moved to the tail before lval is written into the slot. L-value form takes ownership of lval on success.
Use when iteration order is not meaningful (sets, work queues with no ordering requirement, etc.). Faster than VecInsertL for non-tail inserts because no range shift is performed.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in,out | Vector handle. |
lval |
in | Addressable element to insert. |
idx |
in | Position in [0, length]. |
Success
Returns true. The vector length grows by one. The element that previously sat at idx now sits at the new tail; lval’s value occupies idx. When the vector has no copy_init handler, lval has been zeroed (moved-from); otherwise lval is unchanged.
Failure
Returns false on allocation failure. Both vector and lval are unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
// Test VecInsertFastL zero-on-take behavior with complex structures
bool test_lvalue_zero_on_take_fast_insert(void) {
WriteFmt("Testing VecInsertFastL zero-on-take with complex structures\n");
bool result = true; int values1[] = {10, 20, 30};
ComplexItem item1 = InitComplexItem("Fast Item 1", values1, 3);
VecInsertFastL(&vec, item1, 0);
// Check that the item was zeroed
int values2[] = {40, 50, 60};
ComplexItem item2 = InitComplexItem("Fast Item 2", values2, 3);
VecInsertFastL(&vec, item2, 2);
// Check that the item was zeroed
int values3[] = {70, 80, 90};
ComplexItem item3 = InitComplexItem("Fast Item 3", values3, 3);
VecInsertFastL(&vec, item3, VecLen(&vec));
// Check that the item was zeroed
- In
Vec.Insert.c:405:
// Test L-value fast insert
int fast_value = 80;
VecInsertFastL(&vec, fast_value, 3);
// Check that the element was inserted
- In
Vec.Insert.c:472:
// Test VecInsertFastL
int val4 = 70;
VecInsertFastL(&vec, val4, 2);
result = result && (val4 == 0); // Should be zeroed
- In
Insert.h:142:
/// TAGS: Vec, Insert, Fast
///
#define VecInsertFast(v, lval, idx) VecInsertFastL((v), (lval), (idx))
///
- In
Insert.h:605:
#define VecMustInsertFastL(v, lval, idx) \
do { \
if (!VecInsertFastL((v), (lval), (idx))) { \
LOG_FATAL("VecMustInsertFastL failed"); \
} \- In
Insert.h:430:
/// TAGS: Str, Insert, Char, LValue, Fast, Unordered
///
#define StrInsertFastL(str, lval, idx) VecInsertFastL((str), (lval), (idx))
///
Last updated on