diff -r 75ae1dccd101 -r 0458bff0b1cd src/linked_list.c --- a/src/linked_list.c Tue Oct 05 16:33:11 2021 +0200 +++ b/src/linked_list.c Wed Oct 06 14:10:19 2021 +0200 @@ -212,6 +212,7 @@ #define CX_LL_LOC_PREV offsetof(cx_linked_list_node, prev) #define CX_LL_LOC_NEXT offsetof(cx_linked_list_node, next) +#define CX_LL_LOC_DATA offsetof(cx_linked_list_node, payload) typedef struct { cx_list_s base; @@ -380,13 +381,28 @@ return last == NULL ? NULL : *(void **) last->payload; } +static void cx_ll_sort(cx_list_s *list) { + cx_linked_list *ll = (cx_linked_list *) list; + cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, + CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, + 0, list->cmpfunc); +} + +static void cx_pll_sort(cx_list_s *list) { + cx_linked_list *ll = (cx_linked_list *) list; + cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, + CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, + 1, list->cmpfunc); +} + static cx_list_class cx_linked_list_class = { cx_ll_add, cx_ll_insert, cx_ll_remove, cx_ll_at, cx_ll_find, - cx_ll_last + cx_ll_last, + cx_ll_sort }; static cx_list_class cx_pointer_linked_list_class = { @@ -395,7 +411,8 @@ cx_ll_remove, cx_pll_at, cx_pll_find, - cx_pll_last + cx_pll_last, + cx_pll_sort }; CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size) {