Mon, 09 Sep 2013 11:55:14 +0200
fixed some includes
71 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
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 | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
13 | 29 | #include "dlist.h" |
30 | ||
15
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
31 | UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) { |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
32 | UcxDlist *ret = NULL; |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
33 | while (l != NULL) { |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
34 | if (fnc != NULL) { |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
35 | ret = ucx_dlist_append(ret, fnc(l->data, data)); |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
36 | } else { |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
37 | ret = ucx_dlist_append(ret, l->data); |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
38 | } |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
39 | l = l->next; |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
40 | } |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
41 | return ret; |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
42 | } |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
43 | |
71 | 44 | int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2, |
45 | cmp_func fnc, void* data) { | |
15
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
46 | if (l1 == l2) return 1; |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
47 | |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
48 | while (l1 != NULL && l2 != NULL) { |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
49 | if (fnc == NULL) { |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
50 | if (l1->data != l2->data) return 0; |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
51 | } else { |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
52 | if (fnc(l1->data, l2->data, data) != 0) return 0; |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
53 | } |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
54 | l1 = l1->next; |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
55 | l2 = l2->next; |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
56 | } |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
57 | |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
58 | return (l1 == NULL && l2 == NULL); |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
59 | } |
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
60 | |
13 | 61 | void ucx_dlist_free(UcxDlist *l) { |
62 | UcxDlist *e = l, *f; | |
63 | while (e != NULL) { | |
64 | f = e; | |
65 | e = e->next; | |
66 | free(f); | |
67 | } | |
68 | } | |
69 | ||
70 | UcxDlist *ucx_dlist_append(UcxDlist *l, void *data) { | |
71 | UcxDlist *nl = (UcxDlist*) malloc(sizeof(UcxDlist)); | |
72 | if (nl == NULL) return NULL; | |
15
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
73 | |
13 | 74 | nl->data = data; |
75 | nl->next = NULL; | |
76 | if (l == NULL) { | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
77 | nl->prev = NULL; |
13 | 78 | return nl; |
79 | } else { | |
80 | UcxDlist *t = ucx_dlist_last(l); | |
81 | t->next = nl; | |
82 | nl->prev = t; | |
83 | return l; | |
84 | } | |
85 | } | |
86 | ||
87 | UcxDlist *ucx_dlist_prepend(UcxDlist *l, void *data) { | |
88 | UcxDlist *nl = ucx_dlist_append(NULL, data); | |
89 | if (nl == NULL) return NULL; | |
15
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
90 | |
13 | 91 | if (l != NULL) { |
92 | nl->next = l; | |
93 | l->prev = nl; | |
94 | } | |
95 | return nl; | |
96 | } | |
97 | ||
98 | UcxDlist *ucx_dlist_concat(UcxDlist *l1, UcxDlist *l2) { | |
99 | if (l1 == NULL) { | |
100 | return l2; | |
101 | } else { | |
102 | UcxDlist *last = ucx_dlist_last(l1); | |
103 | last->next = l2; | |
104 | l2->prev = last; | |
105 | return l1; | |
106 | } | |
107 | } | |
108 | ||
71 | 109 | UcxDlist *ucx_dlist_last(const UcxDlist *l) { |
13 | 110 | if (l == NULL) return NULL; |
15
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
111 | |
71 | 112 | const UcxDlist *e = l; |
13 | 113 | while (e->next != NULL) { |
114 | e = e->next; | |
115 | } | |
71 | 116 | return (UcxDlist*)e; |
13 | 117 | } |
118 | ||
71 | 119 | UcxDlist *ucx_dlist_get(const UcxDlist *l, int index) { |
13 | 120 | if (l == NULL) return NULL; |
121 | ||
71 | 122 | const UcxDlist *e = l; |
13 | 123 | while (e->next != NULL && index > 0) { |
124 | e = e->next; | |
125 | index--; | |
126 | } | |
15
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
127 | |
71 | 128 | return (UcxDlist*)(index == 0 ? e : NULL); |
13 | 129 | } |
130 | ||
71 | 131 | int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata) { |
132 | UCX_FOREACH(UcxDlist*, l, e) { | |
133 | if (!fnc(elem, e->data, cmpdata)) { | |
134 | return 1; | |
135 | } | |
136 | } | |
137 | return 0; | |
138 | } | |
139 | ||
140 | size_t ucx_dlist_size(const UcxDlist *l) { | |
13 | 141 | if (l == NULL) return 0; |
15
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
142 | |
71 | 143 | const UcxDlist *e = l; |
13 | 144 | size_t s = 1; |
145 | while (e->next != NULL) { | |
146 | e = e->next; | |
147 | s++; | |
148 | } | |
149 | ||
150 | return s; | |
151 | } | |
152 | ||
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
153 | UcxDlist *ucx_dlist_sort_merge(int length, |
71 | 154 | UcxDlist* restrict ls, UcxDlist* restrict le, UcxDlist* restrict re, |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
155 | cmp_func fnc, void* data) { |
71 | 156 | |
157 | UcxDlist** sorted = (UcxDlist**) malloc(sizeof(UcxDlist*)*length); | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
158 | UcxDlist *rc, *lc; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
159 | |
71 | 160 | lc = ls; rc = le; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
161 | int n = 0; |
71 | 162 | while (lc && lc != le && rc != re) { |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
163 | if (fnc(lc->data, rc->data, data) <= 0) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
164 | sorted[n] = lc; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
165 | lc = lc->next; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
166 | } else { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
167 | sorted[n] = rc; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
168 | rc = rc->next; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
169 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
170 | n++; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
171 | } |
71 | 172 | while (lc && lc != le) { |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
173 | sorted[n] = lc; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
174 | lc = lc->next; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
175 | n++; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
176 | } |
71 | 177 | while (rc && rc != re) { |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
178 | sorted[n] = rc; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
179 | rc = rc->next; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
180 | n++; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
181 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
182 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
183 | // Update pointer |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
184 | sorted[0]->prev = NULL; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
185 | for (int i = 0 ; i < length-1 ; i++) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
186 | sorted[i]->next = sorted[i+1]; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
187 | sorted[i+1]->prev = sorted[i]; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
188 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
189 | sorted[length-1]->next = NULL; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
190 | |
71 | 191 | UcxDlist *ret = sorted[0]; |
192 | free(sorted); | |
193 | return ret; | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
194 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
195 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
196 | UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
197 | if (l == NULL) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
198 | return NULL; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
199 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
200 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
201 | UcxDlist *lc; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
202 | int ln = 1; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
203 | |
71 | 204 | UcxDlist *restrict ls = l, *restrict le, *restrict re; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
205 | lc = ls; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
206 | while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
207 | lc = lc->next; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
208 | ln++; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
209 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
210 | le = lc->next; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
211 | |
71 | 212 | if (le == NULL) { |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
213 | return l; // this list is already sorted :) |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
214 | } else { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
215 | UcxDlist *rc; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
216 | int rn = 1; |
71 | 217 | rc = le; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
218 | while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
219 | rc = rc->next; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
220 | rn++; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
221 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
222 | re = rc->next; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
223 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
224 | // Something left? Sort it! |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
225 | UcxDlist *remainder = re; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
226 | size_t remainder_length = ucx_dlist_size(remainder); |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
227 | if (remainder != NULL) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
228 | remainder = ucx_dlist_sort(remainder, fnc, data); |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
229 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
230 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
231 | // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
232 | UcxDlist *sorted = ucx_dlist_sort_merge(ln+rn, |
71 | 233 | ls, le, re, |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
234 | fnc, data); |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
235 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
236 | // merge sorted list with (also sorted) remainder |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
237 | l = ucx_dlist_sort_merge(ln+rn+remainder_length, |
71 | 238 | sorted, remainder, NULL, fnc, data); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
239 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
240 | return l; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
241 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
242 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
243 | |
13 | 244 | /* dlist specific functions */ |
71 | 245 | UcxDlist *ucx_dlist_first(const UcxDlist *l) { |
13 | 246 | if (l == NULL) return NULL; |
15
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
247 | |
71 | 248 | const UcxDlist *e = l; |
13 | 249 | while (e->prev != NULL) { |
250 | e = e->prev; | |
251 | } | |
71 | 252 | return (UcxDlist *)e; |
13 | 253 | } |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
254 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
255 | UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
256 | if (e->prev == NULL) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
257 | if(e->next != NULL) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
258 | e->next->prev = NULL; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
259 | l = e->next; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
260 | } else { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
261 | l = NULL; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
262 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
263 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
264 | } else { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
265 | e->prev->next = e->next; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
266 | e->next->prev = e->prev; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
267 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
268 | free(e); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
269 | return l; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
270 | } |