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 UcxDlist *sorted[length]; |
120 ucx_dynarray_new(UcxDlist*, sorted, length); |
121 UcxDlist *rc, *lc; |
121 UcxDlist *rc, *lc; |
122 |
122 |
123 lc = ls; rc = le; |
123 lc = ls; rc = le; |
124 int n = 0; |
124 int n = 0; |
125 while (lc && lc != le && rc != re) { |
125 while (lc && lc != le && rc != re) { |
149 sorted[i]->next = sorted[i+1]; |
149 sorted[i]->next = sorted[i+1]; |
150 sorted[i+1]->prev = sorted[i]; |
150 sorted[i+1]->prev = sorted[i]; |
151 } |
151 } |
152 sorted[length-1]->next = NULL; |
152 sorted[length-1]->next = NULL; |
153 |
153 |
154 return sorted[0]; |
154 UcxDlist *ret = sorted[0]; |
|
155 ucx_dynarray_free(sorted); |
|
156 return ret; |
155 } |
157 } |
156 |
158 |
157 UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data) { |
159 UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data) { |
158 if (l == NULL) { |
160 if (l == NULL) { |
159 return NULL; |
161 return NULL; |