src/array_list.c

changeset 1622
27e7a4bf1a39
parent 1621
c52a4c67e29e
equal deleted inserted replaced
1621:c52a4c67e29e 1622:27e7a4bf1a39
129 array->size += n; 129 array->size += n;
130 130
131 return 0; 131 return 0;
132 } 132 }
133 133
134 int cx_array_insert_sorted_s_( 134 int cx_array_insert_sorted_c_(
135 const CxAllocator *allocator, 135 const CxAllocator *allocator,
136 CxArray *array, 136 CxArray *array,
137 size_t elem_size, 137 size_t elem_size,
138 const void *sorted_data, 138 const void *sorted_data,
139 size_t n, 139 size_t n,
140 bool allow_duplicates,
141 cx_compare_func2 cmp_func, 140 cx_compare_func2 cmp_func,
142 void *context 141 void *context,
142 bool allow_duplicates
143 ) { 143 ) {
144 // assert pointers 144 // assert pointers
145 assert(allocator != NULL); 145 assert(allocator != NULL);
146 assert(array != NULL); 146 assert(array != NULL);
147 assert(cmp_func != NULL); 147 assert(cmp_func != NULL);
341 341
342 int cx_array_insert_sorted_( 342 int cx_array_insert_sorted_(
343 const CxAllocator *allocator, 343 const CxAllocator *allocator,
344 CxArray *array, 344 CxArray *array,
345 size_t elem_size, 345 size_t elem_size,
346 cx_compare_func cmp_func,
347 const void *sorted_data, 346 const void *sorted_data,
348 size_t n, 347 size_t n,
348 cx_compare_func cmp_func,
349 bool allow_duplicates 349 bool allow_duplicates
350 ) { 350 ) {
351 cx_compare_func_wrapper wrapper = {cmp_func}; 351 cx_compare_func_wrapper wrapper = {cmp_func};
352 return cx_array_insert_sorted_s_(allocator, array, elem_size, sorted_data, 352 return cx_array_insert_sorted_c_(allocator, array, elem_size, sorted_data,
353 n, allow_duplicates, cx_acmp_wrap, &wrapper); 353 n, cx_acmp_wrap, &wrapper, allow_duplicates);
354 } 354 }
355 355
356 #ifndef WITH_QSORT_R 356 #ifndef WITH_QSORT_R
357 static thread_local cx_compare_func2 cx_array_fn_for_qsort; 357 static thread_local cx_compare_func2 cx_array_fn_for_qsort;
358 static thread_local void *cx_array_context_for_qsort; 358 static thread_local void *cx_array_context_for_qsort;
662 cx_array_list *arl = (cx_array_list *) list; 662 cx_array_list *arl = (cx_array_list *) list;
663 CxArray wrap = { 663 CxArray wrap = {
664 arl->data, list->collection.size, arl->capacity 664 arl->data, list->collection.size, arl->capacity
665 }; 665 };
666 666
667 if (cx_array_insert_sorted_s_( 667 if (cx_array_insert_sorted_c_(
668 list->collection.allocator, 668 list->collection.allocator,
669 &wrap, 669 &wrap,
670 list->collection.elem_size, 670 list->collection.elem_size,
671 sorted_data, 671 sorted_data,
672 n, 672 n,
673 allow_duplicates,
674 cx_list_compare_wrapper, 673 cx_list_compare_wrapper,
675 list 674 list,
675 allow_duplicates
676 )) { 676 )) {
677 // array list implementation is "all or nothing" 677 // array list implementation is "all or nothing"
678 return 0; // LCOV_EXCL_LINE 678 return 0; // LCOV_EXCL_LINE
679 } 679 }
680 arl->data = wrap.data; 680 arl->data = wrap.data;

mercurial