C Collections

cvector · Section 3

cvector_find

cvector_find - find the index of the first occurrence of an element

C Collections (libccollections, -lccollections)

#include <ccollections/cvector.h>
 
size_t cvector_find(cvec v, const void *elem,
                    ccol_comparison_proc cmp);

Scans the vector linearly and returns the zero-based index of the first
element equal to *elem. With a NULL cmp the elements are compared with
memcmp over the element size, that is byte by byte.

v     Vector to search (must not be NULL)
elem  Pointer to the value to search for
cmp   Comparison function (int(*)(const void*,const void*)), or NULL
      to use memcmp

Zero-based index of the first element that matches.
ccol_invalid_size when there is no match, and when elem is NULL.

O(n). Asserts if v is NULL.
 
With a NULL cmp, structs with padding bytes may not compare correctly.

cvec_find(3)