VecRemoveFast
Description
Remove the element at idx without preserving order: the previously-last element is swapped into the removed slot. Faster than VecRemove because no range shift is performed.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in,out | Vector handle. |
ptr |
out | Optional destination for the removed element. Pass NULL to discard it (the configured copy_deinit is invoked instead). |
idx |
in | Position in [0, length). |
Success
Returns to the caller. The vector length shrinks by one; the previously-last element now occupies index idx (when idx was not already the last index). When ptr is non-NULL, the removed value has been bit-copied into *ptr and ownership transfers to the caller. When ptr is NULL and copy_deinit is configured, the handler is invoked on the removed element.
Failure
Function cannot fail. An out-of-range idx is treated as a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
VecCharPtr.c:278:
size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
char *str;
VecRemoveFast(vec, &str, index);
// char_ptr_deinit is called automatically by the vector
}- In
VecStr.c:284:
size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
Str str;
VecRemoveFast(vec, &str, index);
// StrDeinit is called automatically by the vector
}- In
VecInt.c:225:
if (idx < VecLen(vec)) {
i32 removed;
VecRemoveFast(vec, &removed, idx);
}
break;- In
Remove.h:206:
/// TAGS: Vec, Delete, Fast, Unordered
///
#define VecDeleteFast(v, idx) VecRemoveFast((v), (VEC_DATATYPE(v) *)NULL, (idx))
///
- In
Remove.h:87:
/// TAGS: Str, Remove, Char, Fast, Unordered
///
#define StrRemoveFast(str, chr, idx) VecRemoveFast((str), (chr), (idx))
///
Last updated on