1.1 --- a/src/linked_list.c Tue Oct 05 16:33:11 2021 +0200 1.2 +++ b/src/linked_list.c Wed Oct 06 14:10:19 2021 +0200 1.3 @@ -212,6 +212,7 @@ 1.4 1.5 #define CX_LL_LOC_PREV offsetof(cx_linked_list_node, prev) 1.6 #define CX_LL_LOC_NEXT offsetof(cx_linked_list_node, next) 1.7 +#define CX_LL_LOC_DATA offsetof(cx_linked_list_node, payload) 1.8 1.9 typedef struct { 1.10 cx_list_s base; 1.11 @@ -380,13 +381,28 @@ 1.12 return last == NULL ? NULL : *(void **) last->payload; 1.13 } 1.14 1.15 +static void cx_ll_sort(cx_list_s *list) { 1.16 + cx_linked_list *ll = (cx_linked_list *) list; 1.17 + cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, 1.18 + CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.19 + 0, list->cmpfunc); 1.20 +} 1.21 + 1.22 +static void cx_pll_sort(cx_list_s *list) { 1.23 + cx_linked_list *ll = (cx_linked_list *) list; 1.24 + cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, 1.25 + CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.26 + 1, list->cmpfunc); 1.27 +} 1.28 + 1.29 static cx_list_class cx_linked_list_class = { 1.30 cx_ll_add, 1.31 cx_ll_insert, 1.32 cx_ll_remove, 1.33 cx_ll_at, 1.34 cx_ll_find, 1.35 - cx_ll_last 1.36 + cx_ll_last, 1.37 + cx_ll_sort 1.38 }; 1.39 1.40 static cx_list_class cx_pointer_linked_list_class = { 1.41 @@ -395,7 +411,8 @@ 1.42 cx_ll_remove, 1.43 cx_pll_at, 1.44 cx_pll_find, 1.45 - cx_pll_last 1.46 + cx_pll_last, 1.47 + cx_pll_sort 1.48 }; 1.49 1.50 CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size) {