C Collections

cvector · Section 3

cvector_push_back

cvector_push_back - append an element to the end of the vector

C Collections (libccollections, -lccollections)

#include <ccollections/cvector.h>
 
ccol_retval cvector_push_back(cvec v, const void *new_elem);

Adds a new element at the end of the vector, which doubles its capacity by
itself when it is full. The element is copied in with an assignment that
the library picks from the element size.

v         Vector to append to
new_elem  Pointer to the element to append (must not be NULL)

ccol_success          - The element was appended
ccol_invalid_args     - new_elem is NULL
ccol_container_full   - The vector has reached ccol_max_elem_count
ccol_not_enough_memory - Growing the capacity failed

Amortized O(1). The element is copied into the vector, and a full vector
doubles its capacity. Asserts if v is NULL.
 
new_elem can safely point into the backing buffer of v, for example a
pointer from cvector_data_ptr(3) or cvector_at(3); a capacity growth
started by this call doesn't invalidate it.

cvector_pop_back(3), cvec_push(3)