src/list.c

changeset 291
deb0035635eb
parent 277
f819fe5e20f5
child 323
b8c49e7a1dba
equal deleted inserted replaced
290:d5d6ab809ad3 291:deb0035635eb
140 last->next = nl; 140 last->next = nl;
141 return l; 141 return l;
142 } 142 }
143 } 143 }
144 144
145 UcxList *ucx_list_prepend_once(UcxList *l, void *data,
146 cmp_func cmpfnc, void *cmpdata) {
147 return ucx_list_prepend_once_a(ucx_default_allocator(), l,
148 data, cmpfnc, cmpdata);
149 }
150
151 UcxList *ucx_list_prepend_once_a(UcxAllocator *alloc, UcxList *l, void *data,
152 cmp_func cmpfnc, void *cmpdata) {
153
154 UcxList* first = ucx_list_first(l);
155 {
156 UcxList *e = first;
157 while (e) {
158 if (cmpfnc(e->data, data, cmpdata) == 0) {
159 return l;
160 }
161 e = e->next;
162 }
163 }
164
165 UcxList *nl = ucx_list_append_a(alloc, NULL, data);
166 if (!nl) {
167 return NULL;
168 }
169
170 if (first) {
171 nl->next = first;
172 first->prev = nl;
173 }
174
175 return nl;
176 }
177
145 UcxList *ucx_list_prepend(UcxList *l, void *data) { 178 UcxList *ucx_list_prepend(UcxList *l, void *data) {
146 return ucx_list_prepend_a(ucx_default_allocator(), l, data); 179 return ucx_list_prepend_a(ucx_default_allocator(), l, data);
147 } 180 }
148 181
149 UcxList *ucx_list_prepend_a(UcxAllocator *alloc, UcxList *l, void *data) { 182 UcxList *ucx_list_prepend_a(UcxAllocator *alloc, UcxList *l, void *data) {

mercurial