115 } |
115 } |
116 |
116 |
117 UcxDlist *ucx_dlist_sort_merge(int length, |
117 UcxDlist *ucx_dlist_sort_merge(int length, |
118 UcxDlist* restrict ls, UcxDlist* restrict le, UcxDlist* restrict re, |
118 UcxDlist* restrict ls, UcxDlist* restrict le, UcxDlist* restrict re, |
119 cmp_func fnc, void* data) { |
119 cmp_func fnc, void* data) { |
120 ucx_dynarray_new(UcxDlist*, sorted, length); |
120 |
|
121 UcxDlist** sorted = (UcxDlist**) malloc(sizeof(UcxDlist*)*length); |
121 UcxDlist *rc, *lc; |
122 UcxDlist *rc, *lc; |
122 |
123 |
123 lc = ls; rc = le; |
124 lc = ls; rc = le; |
124 int n = 0; |
125 int n = 0; |
125 while (lc && lc != le && rc != re) { |
126 while (lc && lc != le && rc != re) { |
150 sorted[i+1]->prev = sorted[i]; |
151 sorted[i+1]->prev = sorted[i]; |
151 } |
152 } |
152 sorted[length-1]->next = NULL; |
153 sorted[length-1]->next = NULL; |
153 |
154 |
154 UcxDlist *ret = sorted[0]; |
155 UcxDlist *ret = sorted[0]; |
155 ucx_dynarray_free(sorted); |
156 free(sorted); |
156 return ret; |
157 return ret; |
157 } |
158 } |
158 |
159 |
159 UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data) { |
160 UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data) { |
160 if (l == NULL) { |
161 if (l == NULL) { |