diff -r cdce47f34d48 -r ee84ac776cbc src/cx/list.h --- a/src/cx/list.h Thu Aug 29 20:48:15 2024 +0200 +++ b/src/cx/list.h Thu Aug 29 21:30:52 2024 +0200 @@ -88,6 +88,7 @@ /** * Member function for inserting multiple elements. * Implementors SHOULD see to performant implementations for corner cases. + * @see cx_list_default_insert_array() */ size_t (*insert_array)( struct cx_list_s *list, @@ -120,6 +121,7 @@ /** * Member function for swapping two elements. + * @see cx_list_default_swap() */ int (*swap)( struct cx_list_s *list, @@ -146,11 +148,14 @@ /** * Member function for sorting the list in-place. + * @see cx_list_default_sort() */ void (*sort)(struct cx_list_s *list); /** - * Member function for comparing this list to another list of the same type. + * Optional member function for comparing this list + * to another list of the same type. + * If set to \c NULL, comparison won't be optimized. */ int (*compare)( struct cx_list_s const *list, @@ -173,6 +178,55 @@ }; /** + * Default implementation of an array insert. + * + * This function uses the element insert function for each element of the array. + * + * Use this in your own list class if you do not want to implement an optimized + * version for your list. + * + * @param list the list + * @param index the index where to insert the data + * @param data a pointer to the array of data to insert + * @param n the number of elements to insert + * @return the number of elements actually inserted + */ +__attribute__((__nonnull__)) +size_t cx_list_default_insert_array( + struct cx_list_s *list, + size_t index, + void const *data, + size_t n +); + +/** + * Default unoptimized sort implementation. + * + * This function will copy all data to an array, sort the array with standard + * qsort, and then copy the data back to the list memory. + * + * Use this in your own list class if you do not want to implement an optimized + * version for your list. + * + * @param list the list that shall be sorted + */ +__attribute__((__nonnull__)) +void cx_list_default_sort(struct cx_list_s *list); + +/** + * Default unoptimized swap implementation. + * + * Use this in your own list class if you do not want to implement an optimized + * version for your list. + * + * @param list the list in which to swap + * @param i index of one element + * @param j index of the other element + */ +__attribute__((__nonnull__)) +int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j); + +/** * Common type for all list implementations. */ typedef struct cx_list_s CxList;