1.1 --- a/src/linked_list.c Sun Nov 20 21:08:36 2022 +0100 1.2 +++ b/src/linked_list.c Wed Nov 23 22:40:55 2022 +0100 1.3 @@ -540,6 +540,20 @@ 1.4 return cx_ll_insert(list, list->size, elem); 1.5 } 1.6 1.7 +static size_t cx_ll_add_array( 1.8 + struct cx_list_s *list, 1.9 + void const *array, 1.10 + size_t n 1.11 +) { 1.12 + // TODO: redirect to cx_ll_insert_array 1.13 + cx_for_n (i, n) { 1.14 + if (cx_ll_add(list, ((char const *) array) + i * list->itemsize)) { 1.15 + return i; 1.16 + } 1.17 + } 1.18 + return n; 1.19 +} 1.20 + 1.21 static int cx_pll_insert( 1.22 struct cx_list_s *list, 1.23 size_t index, 1.24 @@ -727,6 +741,7 @@ 1.25 static cx_list_class cx_linked_list_class = { 1.26 cx_ll_destructor, 1.27 cx_ll_add, 1.28 + cx_ll_add_array, 1.29 cx_ll_insert, 1.30 cx_ll_insert_iter, 1.31 cx_ll_remove, 1.32 @@ -741,6 +756,7 @@ 1.33 static cx_list_class cx_pointer_linked_list_class = { 1.34 cx_ll_destructor, 1.35 cx_pll_add, 1.36 + cx_ll_add_array, 1.37 cx_pll_insert, 1.38 cx_pll_insert_iter, 1.39 cx_ll_remove, 1.40 @@ -786,22 +802,3 @@ 1.41 1.42 return (CxList *) list; 1.43 } 1.44 - 1.45 -CxList *cxLinkedListFromArray( 1.46 - CxAllocator const *allocator, 1.47 - CxListComparator comparator, 1.48 - size_t item_size, 1.49 - size_t num_items, 1.50 - void const *array 1.51 -) { 1.52 - CxList *list = cxLinkedListCreate(allocator, comparator, item_size); 1.53 - if (list == NULL) return NULL; 1.54 - cx_for_n (i, num_items) { 1.55 - if (0 != cxListAdd(list, ((const unsigned char *) array) + i * item_size)) { 1.56 - cx_ll_destructor(list); 1.57 - cxFree(allocator, list); 1.58 - return NULL; 1.59 - } 1.60 - } 1.61 - return list; 1.62 -}