1 /* |
1 /* |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * |
3 * |
4 * Copyright 2016 Olaf Wintermann. All rights reserved. |
4 * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: |
7 * modification, are permitted provided that the following conditions are met: |
8 * |
8 * |
9 * 1. Redistributions of source code must retain the above copyright |
9 * 1. Redistributions of source code must retain the above copyright |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
29 #include "list.h" |
29 #include "ucx/list.h" |
30 |
30 |
31 UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) { |
31 UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) { |
32 return ucx_list_clone_a(ucx_default_allocator(), l, fnc, data); |
32 return ucx_list_clone_a(ucx_default_allocator(), l, fnc, data); |
33 } |
33 } |
34 |
34 |
239 |
239 |
240 return s; |
240 return s; |
241 } |
241 } |
242 |
242 |
243 static UcxList *ucx_list_sort_merge(int length, |
243 static UcxList *ucx_list_sort_merge(int length, |
244 UcxList* restrict ls, UcxList* restrict le, UcxList* restrict re, |
244 UcxList* ls, UcxList* le, UcxList* re, |
245 cmp_func fnc, void* data) { |
245 cmp_func fnc, void* data) { |
246 |
246 |
247 UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length); |
247 UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length); |
248 UcxList *rc, *lc; |
248 UcxList *rc, *lc; |
249 |
249 |
289 } |
289 } |
290 |
290 |
291 UcxList *lc; |
291 UcxList *lc; |
292 int ln = 1; |
292 int ln = 1; |
293 |
293 |
294 UcxList *restrict ls = l, *restrict le, *restrict re; |
294 UcxList *ls = l, *le, *re; |
295 |
295 |
296 // check how many elements are already sorted |
296 // check how many elements are already sorted |
297 lc = ls; |
297 lc = ls; |
298 while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) { |
298 while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) { |
299 lc = lc->next; |
299 lc = lc->next; |