Skip to content
VecRemoveRange

VecRemoveRange

Description

Remove count elements starting at start and optionally move them out to the provided buffer. Order of remaining trailing elements is preserved.

Parameters

Name Direction Description
v in,out Vector handle.
ptr out Optional destination buffer of at least count element slots. Pass NULL to discard the removed elements (the configured copy_deinit is invoked instead).
start in First removed index.
count in Number of elements to remove.

Success

Returns to the caller. The vector length shrinks by count; elements that previously sat at indices >= start + count have shifted left by count. When ptr is non-NULL, the removed values have been bit-copied into *ptr in order (copy_deinit is not invoked - ownership transfers). When ptr is NULL and copy_deinit is configured, the handler is invoked on each removed element.

Failure

Function cannot fail. start + count exceeding length is a caller bug and aborts via LOG_FATAL.

Usage example (Cross-references)

Usage examples (Cross-references)
    /// TAGS: Vec, Delete, Range
    ///
    #define VecDeleteRange(v, start, count) VecRemoveRange((v), (VEC_DATATYPE(v) *)NULL, (start), (count))
    
    ///
    /// TAGS: Str, Remove, Range
    ///
    #define StrRemoveRange(str, rd, start, count) VecRemoveRange((str), (rd), (start), (count))
    
    ///
                if (len > 0 && start < len && count > 0 && start + count <= len) {
                    i32 removed_items[16];
                    VecRemoveRange(vec, removed_items, start, count);
                }
                break;
                    size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
                    size_t count = extract_u32(data, offset, data_size) % (VecLen(vec) - index + 1);
                    VecRemoveRange(vec, (char **)NULL, index, count);
                }
                break;
                    size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
                    size_t count = extract_u32(data, offset, data_size) % (VecLen(vec) - index + 1);
                    VecRemoveRange(vec, (Str *)NULL, index, count);
                }
                break;
        ElemVec vec = make_elem_vec(5);           // ids 0..4
    
        VecRemoveRange(&vec, (Elem *)NULL, 0, 2); // remove ids {0,1}
    
        bool result = (g_freed[0] == 1 && g_freed[1] == 1);
        ElemVec vec = make_elem_vec(5);           // ids 0..4
    
        VecRemoveRange(&vec, (Elem *)NULL, 0, 2); // remove ids {0,1}
    
        bool result = (g_freed[0] == 1 && g_freed[1] == 1);
        ElemVec vec = make_elem_vec(5);           // ids 0..4
    
        VecRemoveRange(&vec, (Elem *)NULL, 0, 2); // remove ids {0,1}; id 2 survives
    
        // Survivor id 2 must be untouched by the removal.
        ElemVec vec = make_elem_vec(5);           // ids 0..4
    
        VecRemoveRange(&vec, (Elem *)NULL, 0, 3); // remove ids {0,1,2}
    
        bool result = (g_freed[0] == 1 && g_freed[1] == 1 && g_freed[2] == 1);
        ElemVec vec = make_elem_vec(5);           // ids 0..4
    
        VecRemoveRange(&vec, (Elem *)NULL, 1, 3); // remove ids {1,2,3}
    
        bool result = (g_freed[1] == 1 && g_freed[2] == 1 && g_freed[3] == 1);
Last updated on