src/list.c

changeset 291
deb0035635eb
parent 277
f819fe5e20f5
child 323
b8c49e7a1dba
     1.1 --- a/src/list.c	Wed May 09 20:15:10 2018 +0200
     1.2 +++ b/src/list.c	Fri May 11 17:40:16 2018 +0200
     1.3 @@ -142,6 +142,39 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +UcxList *ucx_list_prepend_once(UcxList *l, void *data,
     1.8 +        cmp_func cmpfnc, void *cmpdata) {
     1.9 +    return ucx_list_prepend_once_a(ucx_default_allocator(), l,
    1.10 +            data, cmpfnc, cmpdata);
    1.11 +}
    1.12 +
    1.13 +UcxList *ucx_list_prepend_once_a(UcxAllocator *alloc, UcxList *l, void *data,
    1.14 +        cmp_func cmpfnc, void *cmpdata) {
    1.15 +
    1.16 +    UcxList* first = ucx_list_first(l);
    1.17 +    {
    1.18 +        UcxList *e = first;
    1.19 +        while (e) {
    1.20 +            if (cmpfnc(e->data, data, cmpdata) == 0) {
    1.21 +                return l;
    1.22 +            }
    1.23 +            e = e->next;
    1.24 +        }
    1.25 +    }
    1.26 +    
    1.27 +    UcxList *nl = ucx_list_append_a(alloc, NULL, data);
    1.28 +    if (!nl) {
    1.29 +        return NULL;
    1.30 +    }
    1.31 +
    1.32 +    if (first) {
    1.33 +        nl->next = first;
    1.34 +        first->prev = nl;
    1.35 +    }
    1.36 +    
    1.37 +    return nl;
    1.38 +}
    1.39 +
    1.40  UcxList *ucx_list_prepend(UcxList *l, void *data) {
    1.41      return ucx_list_prepend_a(ucx_default_allocator(), l, data);
    1.42  }

mercurial