diff -r d5d6ab809ad3 -r deb0035635eb src/list.c --- a/src/list.c Wed May 09 20:15:10 2018 +0200 +++ b/src/list.c Fri May 11 17:40:16 2018 +0200 @@ -142,6 +142,39 @@ } } +UcxList *ucx_list_prepend_once(UcxList *l, void *data, + cmp_func cmpfnc, void *cmpdata) { + return ucx_list_prepend_once_a(ucx_default_allocator(), l, + data, cmpfnc, cmpdata); +} + +UcxList *ucx_list_prepend_once_a(UcxAllocator *alloc, UcxList *l, void *data, + cmp_func cmpfnc, void *cmpdata) { + + UcxList* first = ucx_list_first(l); + { + UcxList *e = first; + while (e) { + if (cmpfnc(e->data, data, cmpdata) == 0) { + return l; + } + e = e->next; + } + } + + UcxList *nl = ucx_list_append_a(alloc, NULL, data); + if (!nl) { + return NULL; + } + + if (first) { + nl->next = first; + first->prev = nl; + } + + return nl; +} + UcxList *ucx_list_prepend(UcxList *l, void *data) { return ucx_list_prepend_a(ucx_default_allocator(), l, data); }