utils/algorithms.h file

Various algorithms.

Contents

Functions

auto algorithms_binary_search_nearby(const void* key, const void* base, size_t nmemb, size_t size, GenericCmpFunc cmp_func, bool return_prev, bool include_equal) -> HOT PURE NONNULL void*
Binary search with the option to find the closest member in a sorted array.

Function documentation

HOT PURE NONNULL void* algorithms_binary_search_nearby(const void* key, const void* base, size_t nmemb, size_t size, GenericCmpFunc cmp_func, bool return_prev, bool include_equal)

Binary search with the option to find the closest member in a sorted array.

Parameters
key
base
nmemb
size
cmp_func
return_prev True to return previous closest element, false for next.
include_equal Include equal elements (if an exact match is found, return it).

All of the parameters except the following are the same as the C std bsearch().