utilities: bsearch and qsort with additional user_data pointer argument
This commit is contained in:
37
src/utils.h
37
src/utils.h
@ -74,4 +74,41 @@ char* obi_format_date(time_t date);
|
||||
void* obi_get_memory_aligned_on_16(int size, int* shift);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Version of quick sort modified to allow the user to provide an
|
||||
* additional pointer sent to the comparison function.
|
||||
*
|
||||
* @param key This is the pointer to the object that serves as key for the search, type-casted as a void*.
|
||||
* @param base This is the pointer to the first object of the array where the search is performed, type-casted as a void*.
|
||||
* @param num This is the number of elements in the array pointed by base.
|
||||
* @param size This is the size in bytes of each element in the array.
|
||||
* @param user_data This is an additional pointer passed to the comparison function.
|
||||
* @param cmp This is the function that compares two elements, eventually with an additional pointer.
|
||||
*
|
||||
* @returns A pointer to an entry in the array that matches the search key.
|
||||
* @retval NULL if key is not found.
|
||||
*
|
||||
* @since January 2017
|
||||
* @author original code modified by Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
void* bsearch_user_data(const void* key, const void* base, size_t num, size_t size, const void* user_data,
|
||||
int (*cmp)(const void *key, const void *elt, const void* user_data));
|
||||
|
||||
|
||||
/**
|
||||
* @brief Version of quick sort modified to allow the user to provide an
|
||||
* additional pointer sent to the comparison function.
|
||||
*
|
||||
* @param aa This is the pointer to the first element of the array to be sorted.
|
||||
* @param n This is the number of elements in the array pointed by base.
|
||||
* @param es This is the size in bytes of each element in the array.
|
||||
* @param user_data This is an additional pointer passed to the comparison function.
|
||||
* @param cmp This is the function that compares two elements, eventually with an additional pointer.
|
||||
*
|
||||
* @since January 2017
|
||||
* @author original code modified by Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
void qsort_user_data(void *aa, size_t n, size_t es, const void *user_data, int (*cmp)(const void *, const void *, const void *));
|
||||
|
||||
|
||||
#endif /* UTILS_H_ */
|
||||
|
Reference in New Issue
Block a user