MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / __array_min_element_impl

Function __array_min_element_impl

array/array.h:282–296  ·  view source on GitHub ↗

* @brief Internal implementation of array_min_element. * * Returns a pointer to the smallest element according to `cmp` * (the first one encountered on ties), or NULL if the array is empty. */

Source from the content-addressed store, hash-verified

280 * @brief Finds an element in the array for which the predicate returns true.
281 */
282#define array_find_if(arr, predicate) \
283 arrayp_find_if_impl((arr).data, array_size(arr), sizeof((arr).data[0]), (predicate))
284
285
286/**
287 * @brief Internal implementation of array_min_element.
288 *
289 * Returns a pointer to the smallest element according to `cmp`
290 * (the first one encountered on ties), or NULL if the array is empty.
291 */
292static inline void *arrayp_min_element_impl(const void *data, size_t count, size_t elem_size,
293 int (*cmp)(const void *, const void *)) {
294 if (count == 0) {
295 return NULL;
296 }
297 unsigned char *ptr = (unsigned char *)(uintptr_t)data;
298 unsigned char *best = ptr;
299 for (size_t i = 1; i < count; i++) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected