ucx/list.c

changeset 229
9db71925eaa8
parent 228
9f385abc72fb
child 250
b7d1317b138e
equal deleted inserted replaced
228:9f385abc72fb 229:9db71925eaa8
157 l->prev = nl; 157 l->prev = nl;
158 } 158 }
159 return nl; 159 return nl;
160 } 160 }
161 161
162 UcxList *ucx_list_prepend_once(UcxList *l, void *data,
163 cmp_func cmpfnc, void* cmpdata) {
164 return ucx_list_prepend_once_a(ucx_default_allocator(), l,
165 data, cmpfnc, cmpdata);
166 }
167
168 UcxList *ucx_list_prepend_once_a(UcxAllocator *alloc, UcxList *l, void *data,
169 cmp_func cmpfnc, void *cmpdata) {
170
171 if (l) {
172 int found = 0;
173 UcxList *first;
174 {
175 UcxList *e = l;
176 while (e) {
177 found |= (cmpfnc(e->data, data, cmpdata) == 0);
178 first = e;
179 e = e->prev;
180 }
181 }
182
183 if (found) {
184 return first;
185 } else {
186 UcxList *nl = ucx_list_append_a(alloc, NULL, data);
187 nl->next = first;
188 first->prev = nl;
189 return nl;
190 }
191 } else {
192 return ucx_list_append_a(alloc, NULL, data);
193 }
194 }
195
196 UcxList *ucx_list_concat(UcxList *l1, UcxList *l2) { 162 UcxList *ucx_list_concat(UcxList *l1, UcxList *l2) {
197 if (l1) { 163 if (l1) {
198 UcxList *last = ucx_list_last(l1); 164 UcxList *last = ucx_list_last(l1);
199 last->next = l2; 165 last->next = l2;
200 if (l2) { 166 if (l2) {

mercurial