--- a/ucx/list.c Mon Feb 04 14:46:11 2019 +0100 +++ b/ucx/list.c Mon Feb 04 17:49:50 2019 +0100 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 2016 Olaf Wintermann. All rights reserved. + * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "list.h" +#include "ucx/list.h" UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) { return ucx_list_clone_a(ucx_default_allocator(), l, fnc, data); @@ -77,6 +77,7 @@ } void ucx_list_free_content(UcxList* list, ucx_destructor destr) { + if (!destr) destr = free; while (list != NULL) { destr(list->data); list = list->next; @@ -106,41 +107,6 @@ } } -UcxList *ucx_list_append_once(UcxList *l, void *data, - cmp_func cmpfnc, void *cmpdata) { - return ucx_list_append_once_a(ucx_default_allocator(), l, - data, cmpfnc, cmpdata); -} - -UcxList *ucx_list_append_once_a(UcxAllocator *alloc, UcxList *l, void *data, - cmp_func cmpfnc, void *cmpdata) { - - UcxList *last = NULL; - { - UcxList *e = l; - while (e) { - if (cmpfnc(e->data, data, cmpdata) == 0) { - return l; - } - last = e; - e = e->next; - } - } - - UcxList *nl = ucx_list_append_a(alloc, NULL, data); - if (!nl) { - return NULL; - } - - if (last == NULL) { - return nl; - } else { - nl->prev = last; - last->next = nl; - return l; - } -} - UcxList *ucx_list_prepend(UcxList *l, void *data) { return ucx_list_prepend_a(ucx_default_allocator(), l, data); } @@ -241,7 +207,7 @@ } static UcxList *ucx_list_sort_merge(int length, - UcxList* restrict ls, UcxList* restrict le, UcxList* restrict re, + UcxList* ls, UcxList* le, UcxList* re, cmp_func fnc, void* data) { UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length); @@ -291,7 +257,7 @@ UcxList *lc; int ln = 1; - UcxList *restrict ls = l, *restrict le, *restrict re; + UcxList *ls = l, *le, *re; // check how many elements are already sorted lc = ls;