diff -r 4bd19279778c -r 9138acaa494b src/linked_list.c --- a/src/linked_list.c Tue Dec 28 14:25:05 2021 +0100 +++ b/src/linked_list.c Tue Dec 28 17:24:18 2021 +0100 @@ -613,13 +613,36 @@ true, list->cmpfunc); } +static int cx_ll_compare( + cx_list_s *list, + cx_list_s *other +) { + cx_linked_list *left = (cx_linked_list *) list; + cx_linked_list *right = (cx_linked_list *) other; + return cx_linked_list_compare(left->begin, right->begin, + CX_LL_LOC_NEXT, CX_LL_LOC_DATA, + false, list->cmpfunc); +} + +static int cx_pll_compare( + cx_list_s *list, + cx_list_s *other +) { + cx_linked_list *left = (cx_linked_list *) list; + cx_linked_list *right = (cx_linked_list *) other; + return cx_linked_list_compare(left->begin, right->begin, + CX_LL_LOC_NEXT, CX_LL_LOC_DATA, + true, 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_sort + cx_ll_sort, + cx_ll_compare }; static cx_list_class cx_pointer_linked_list_class = { @@ -628,7 +651,8 @@ cx_ll_remove, cx_pll_at, cx_pll_find, - cx_pll_sort + cx_pll_sort, + cx_pll_compare }; CxList cxLinkedListCreate( @@ -674,6 +698,24 @@ return (CxList) list; } +CxList cxLinkedListFromArray( + CxAllocator allocator, + CxListComparator comparator, + size_t item_size, + size_t num_items, + const void *array +) { + CxList list = cxLinkedListCreate(allocator, comparator, item_size); + if (list == NULL) return NULL; + for (size_t i = 0; i < num_items; i++) { + if (0 != cxListAdd(list, ((const unsigned char *) array) + i * item_size)) { + cxLinkedListDestroy(list); + return NULL; + } + } + return list; +} + void cxLinkedListDestroy(CxList list) { cx_linked_list *ll = (cx_linked_list *) list;