removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)

Mon, 22 Jul 2013 11:53:39 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 22 Jul 2013 11:53:39 +0200
changeset 122
540d99722f1f
parent 121
311cac04d079
child 123
7fb0f74517c5

removal of single linked list implemenation - step 2: renamed UcxDlist to UcxList (new single implementation)

test/Makefile file | annotate | diff | comparison | revisions
test/dlist_tests.c file | annotate | diff | comparison | revisions
test/dlist_tests.h file | annotate | diff | comparison | revisions
test/list_tests.c file | annotate | diff | comparison | revisions
test/list_tests.h file | annotate | diff | comparison | revisions
test/main.c file | annotate | diff | comparison | revisions
ucx/Makefile file | annotate | diff | comparison | revisions
ucx/dlist.c file | annotate | diff | comparison | revisions
ucx/dlist.h file | annotate | diff | comparison | revisions
ucx/list.c file | annotate | diff | comparison | revisions
ucx/list.h file | annotate | diff | comparison | revisions
     1.1 --- a/test/Makefile	Mon Jul 22 11:39:06 2013 +0200
     1.2 +++ b/test/Makefile	Mon Jul 22 11:53:39 2013 +0200
     1.3 @@ -29,7 +29,7 @@
     1.4  include ../$(CONF).mk
     1.5  
     1.6  SRC  = main.c
     1.7 -SRC += dlist_tests.c
     1.8 +SRC += list_tests.c
     1.9  SRC += mpool_tests.c
    1.10  SRC += map_tests.c
    1.11  SRC += prop_tests.c
     2.1 --- a/test/dlist_tests.c	Mon Jul 22 11:39:06 2013 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,247 +0,0 @@
     2.4 -/*
     2.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 - *
     2.7 - * Copyright 2013 Olaf Wintermann. All rights reserved.
     2.8 - *
     2.9 - * Redistribution and use in source and binary forms, with or without
    2.10 - * modification, are permitted provided that the following conditions are met:
    2.11 - *
    2.12 - *   1. Redistributions of source code must retain the above copyright
    2.13 - *      notice, this list of conditions and the following disclaimer.
    2.14 - *
    2.15 - *   2. Redistributions in binary form must reproduce the above copyright
    2.16 - *      notice, this list of conditions and the following disclaimer in the
    2.17 - *      documentation and/or other materials provided with the distribution.
    2.18 - *
    2.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    2.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    2.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    2.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    2.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    2.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    2.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    2.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    2.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    2.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    2.29 - * POSSIBILITY OF SUCH DAMAGE.
    2.30 - */
    2.31 -
    2.32 -#include "dlist_tests.h"
    2.33 -#include "ucx/utils.h"
    2.34 -
    2.35 -UCX_TEST_IMPLEMENT(test_ucx_dlist_append) {
    2.36 -    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello");
    2.37 -    UCX_TEST_BEGIN
    2.38 -    
    2.39 -    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    2.40 -            "failed");
    2.41 -    
    2.42 -    list = ucx_dlist_append(list, (void*)" World!");
    2.43 -    
    2.44 -    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    2.45 -            "failed");
    2.46 -    UCX_TEST_ASSERT(list->next->next == NULL, "failed");
    2.47 -    UCX_TEST_END
    2.48 -    
    2.49 -    ucx_dlist_free(list);
    2.50 -}
    2.51 -
    2.52 -UCX_TEST_IMPLEMENT(test_ucx_dlist_prepend) {
    2.53 -    UcxDlist *list = ucx_dlist_prepend(NULL, (void*)" World!");
    2.54 -    UCX_TEST_BEGIN
    2.55 -
    2.56 -    list = ucx_dlist_prepend(list, (void*)"Hello");
    2.57 -    
    2.58 -    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    2.59 -            "failed");
    2.60 -    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    2.61 -            "failed");
    2.62 -    UCX_TEST_ASSERT(list->next->next == NULL, "failed");
    2.63 -    
    2.64 -    UCX_TEST_END
    2.65 -    ucx_dlist_free(list);
    2.66 -}
    2.67 -
    2.68 -UCX_TEST_IMPLEMENT(test_ucx_dlist_equals) {
    2.69 -    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello");
    2.70 -    list = ucx_dlist_append(list, (void*)" World!");
    2.71 -    UcxDlist *list2 = ucx_dlist_prepend(NULL, (void*)" World!");
    2.72 -    list2 = ucx_dlist_prepend(list2, (void*)"Hello");
    2.73 -    UcxDlist *list3 = ucx_dlist_prepend(NULL, (void*)" Welt!");
    2.74 -    list3 = ucx_dlist_prepend(list3, (void*)"Hallo");
    2.75 -    UCX_TEST_BEGIN
    2.76 -    
    2.77 -    UCX_TEST_ASSERT(ucx_dlist_equals(list, list2, ucx_strcmp, NULL), "failed");
    2.78 -    UCX_TEST_ASSERT(!ucx_dlist_equals(list, list3, ucx_strcmp, NULL), "failed");
    2.79 -    
    2.80 -    UCX_TEST_END
    2.81 -    ucx_dlist_free(list3);
    2.82 -    ucx_dlist_free(list2);
    2.83 -    ucx_dlist_free(list);
    2.84 -}
    2.85 -
    2.86 -UCX_TEST_IMPLEMENT(test_ucx_dlist_concat) {
    2.87 -    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello");
    2.88 -    UcxDlist *list2 = ucx_dlist_prepend(NULL, (void*)" World!");
    2.89 -    UCX_TEST_BEGIN
    2.90 -    
    2.91 -    list = ucx_dlist_concat(list, list2);
    2.92 -    
    2.93 -    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    2.94 -            "failed");
    2.95 -    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    2.96 -            "failed");
    2.97 -    UCX_TEST_ASSERT(list->next->next == NULL, "failed");
    2.98 -    
    2.99 -    UCX_TEST_END
   2.100 -    ucx_dlist_free(list);
   2.101 -}
   2.102 -
   2.103 -UCX_TEST_IMPLEMENT(test_ucx_dlist_size) {
   2.104 -    UcxDlist *list = ucx_dlist_append(NULL, (void*)"This ");
   2.105 -    UCX_TEST_BEGIN
   2.106 -    list = ucx_dlist_append(list, (void*)"list ");
   2.107 -    list = ucx_dlist_append(list, (void*)"has ");
   2.108 -    list = ucx_dlist_append(list, (void*)"size ");
   2.109 -    list = ucx_dlist_append(list, (void*)"5!");
   2.110 -    
   2.111 -    UCX_TEST_ASSERT(ucx_dlist_size(list) == 5, "failed");
   2.112 -    
   2.113 -    UCX_TEST_END
   2.114 -    ucx_dlist_free(list);
   2.115 -}
   2.116 -
   2.117 -UCX_TEST_IMPLEMENT(test_ucx_dlist_first) {
   2.118 -    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find ");
   2.119 -    UCX_TEST_BEGIN
   2.120 -    list = ucx_dlist_append(list, (void*)"the ");
   2.121 -    list = ucx_dlist_append(list, (void*)"first!");
   2.122 -    
   2.123 -    const char* first = (const char*) (ucx_dlist_first(list)->data);
   2.124 -    
   2.125 -    UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed");
   2.126 -    
   2.127 -    UCX_TEST_END
   2.128 -    ucx_dlist_free(list);
   2.129 -}
   2.130 -
   2.131 -UCX_TEST_IMPLEMENT(test_ucx_dlist_last) {
   2.132 -    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find ");
   2.133 -    UCX_TEST_BEGIN
   2.134 -    list = ucx_dlist_append(list, (void*)"the ");
   2.135 -    list = ucx_dlist_append(list, (void*)"last!");
   2.136 -    
   2.137 -    const char* last = (const char*) (ucx_dlist_last(list)->data);
   2.138 -    
   2.139 -    UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed");
   2.140 -    
   2.141 -    UCX_TEST_END
   2.142 -    ucx_dlist_free(list);
   2.143 -}
   2.144 -
   2.145 -UCX_TEST_IMPLEMENT(test_ucx_dlist_get) {
   2.146 -    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find ");
   2.147 -    UCX_TEST_BEGIN
   2.148 -    list = ucx_dlist_append(list, (void*)"the ");
   2.149 -    list = ucx_dlist_append(list, (void*)"mid!");
   2.150 -    
   2.151 -    const char* mid = (const char*) (ucx_dlist_get(list, 1)->data);
   2.152 -    
   2.153 -    UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed");
   2.154 -    
   2.155 -    UCX_TEST_END
   2.156 -    ucx_dlist_free(list);
   2.157 -}
   2.158 -
   2.159 -UCX_TEST_IMPLEMENT(test_ucx_dlist_contains) {
   2.160 -    UcxDlist *l = ucx_dlist_append(NULL, (void*)"Contains ");
   2.161 -    UCX_TEST_BEGIN
   2.162 -    l = ucx_dlist_append(l, (void*)"a ");
   2.163 -    l = ucx_dlist_append(l, (void*)"string!");
   2.164 -    
   2.165 -    UCX_TEST_ASSERT(ucx_dlist_contains(l,(void*)"a ",ucx_strcmp,NULL),"failed");
   2.166 -    UCX_TEST_ASSERT(!ucx_dlist_contains(l,(void*)"a",ucx_strcmp,NULL),"failed");
   2.167 -    
   2.168 -    UCX_TEST_END
   2.169 -    ucx_dlist_free(l);
   2.170 -}
   2.171 -
   2.172 -UCX_TEST_IMPLEMENT(test_ucx_dlist_remove) {
   2.173 -    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello");
   2.174 -    UCX_TEST_BEGIN
   2.175 -    list = ucx_dlist_append(list, (void*)" fucking");
   2.176 -    list = ucx_dlist_append(list, (void*)" World!");
   2.177 -    
   2.178 -    list = ucx_dlist_remove(list, ucx_dlist_get(list, 1));
   2.179 -    
   2.180 -    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
   2.181 -            "failed");
   2.182 -    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
   2.183 -            "failed");
   2.184 -    UCX_TEST_ASSERT(list->next->next == NULL, "failed");
   2.185 -    
   2.186 -    UCX_TEST_END
   2.187 -    ucx_dlist_free(list);
   2.188 -}
   2.189 -
   2.190 -UCX_TEST_IMPLEMENT(test_ucx_dlist_clone) {
   2.191 -   
   2.192 -    char *hello = (char*)malloc(6);
   2.193 -    char *world = (char*)malloc(8);
   2.194 -    
   2.195 -    memcpy(hello, "Hello", 6);
   2.196 -    memcpy(world, " World!", 8);
   2.197 -    
   2.198 -    UcxDlist *list = ucx_dlist_append(NULL, hello);
   2.199 -    list = ucx_dlist_append(list, world);
   2.200 -    
   2.201 -    UcxDlist *copy = ucx_dlist_clone(list, ucx_strcpy, NULL);
   2.202 -    UCX_TEST_BEGIN
   2.203 -
   2.204 -    UCX_TEST_ASSERT(ucx_dlist_equals(list, copy, ucx_strcmp, NULL), "failed");
   2.205 -    UCX_TEST_ASSERT(hello != copy->data, "first element is no copy");
   2.206 -    UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy");
   2.207 -
   2.208 -    UCX_TEST_END
   2.209 -    free(copy->next->data);
   2.210 -    free(copy->data);
   2.211 -
   2.212 -    free(world);
   2.213 -    free(hello);
   2.214 -    ucx_dlist_free(list);
   2.215 -    ucx_dlist_free(copy);
   2.216 -}
   2.217 -
   2.218 -UCX_TEST_IMPLEMENT(test_ucx_dlist_sort) {
   2.219 -    UcxDlist *list = ucx_dlist_append(NULL, (void*)"this");
   2.220 -    list = ucx_dlist_append(list, (void*)"is");
   2.221 -    list = ucx_dlist_append(list, (void*)"a");
   2.222 -    list = ucx_dlist_append(list, (void*)"test");
   2.223 -    list = ucx_dlist_append(list, (void*)"for");
   2.224 -    list = ucx_dlist_append(list, (void*)"partial");
   2.225 -    list = ucx_dlist_append(list, (void*)"correctness");
   2.226 -
   2.227 -    UcxDlist *expected = ucx_dlist_append(NULL, (void*)"a");
   2.228 -    expected = ucx_dlist_append(expected, (void*)"correctness");
   2.229 -    expected = ucx_dlist_append(expected, (void*)"for");
   2.230 -    expected = ucx_dlist_append(expected, (void*)"is");
   2.231 -    expected = ucx_dlist_append(expected, (void*)"partial");
   2.232 -    expected = ucx_dlist_append(expected, (void*)"test");
   2.233 -    expected = ucx_dlist_append(expected, (void*)"this");
   2.234 -
   2.235 -    list = ucx_dlist_sort(list, ucx_strcmp, NULL);
   2.236 -
   2.237 -    UCX_TEST_BEGIN
   2.238 -    UCX_TEST_ASSERT(
   2.239 -            ucx_dlist_equals(list, expected, ucx_strcmp, NULL), "failed");
   2.240 -    UcxDlist *l = list;
   2.241 -    UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null");
   2.242 -    while (l->next != NULL) {
   2.243 -        UCX_TEST_ASSERT(l->next->prev == l, "prev pointer corrupted");
   2.244 -        l = l->next;
   2.245 -    }
   2.246 -    UCX_TEST_END
   2.247 -
   2.248 -    ucx_dlist_free(expected);
   2.249 -    ucx_dlist_free(list);
   2.250 -}
     3.1 --- a/test/dlist_tests.h	Mon Jul 22 11:39:06 2013 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,64 +0,0 @@
     3.4 -/*
     3.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3.6 - *
     3.7 - * Copyright 2013 Olaf Wintermann. All rights reserved.
     3.8 - *
     3.9 - * Redistribution and use in source and binary forms, with or without
    3.10 - * modification, are permitted provided that the following conditions are met:
    3.11 - *
    3.12 - *   1. Redistributions of source code must retain the above copyright
    3.13 - *      notice, this list of conditions and the following disclaimer.
    3.14 - *
    3.15 - *   2. Redistributions in binary form must reproduce the above copyright
    3.16 - *      notice, this list of conditions and the following disclaimer in the
    3.17 - *      documentation and/or other materials provided with the distribution.
    3.18 - *
    3.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    3.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    3.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    3.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    3.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    3.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    3.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    3.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    3.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    3.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    3.29 - * POSSIBILITY OF SUCH DAMAGE.
    3.30 - */
    3.31 -
    3.32 -#ifndef DLIST_TESTS_H
    3.33 -#define	DLIST_TESTS_H
    3.34 -
    3.35 -#include "main.h"
    3.36 -
    3.37 -#include "ucx/dlist.h"
    3.38 -#include "ucx/test.h"
    3.39 -
    3.40 -#ifdef	__cplusplus
    3.41 -extern "C" {
    3.42 -#endif
    3.43 -
    3.44 -/*
    3.45 - * Assumed to be correct:
    3.46 - *   ucx_dlist_free
    3.47 - */
    3.48 -
    3.49 -UCX_TEST_DECLARE(test_ucx_dlist_append);
    3.50 -UCX_TEST_DECLARE(test_ucx_dlist_prepend);
    3.51 -UCX_TEST_DECLARE(test_ucx_dlist_equals);
    3.52 -UCX_TEST_DECLARE(test_ucx_dlist_concat);
    3.53 -UCX_TEST_DECLARE(test_ucx_dlist_size);
    3.54 -UCX_TEST_DECLARE(test_ucx_dlist_first);
    3.55 -UCX_TEST_DECLARE(test_ucx_dlist_last);
    3.56 -UCX_TEST_DECLARE(test_ucx_dlist_get);
    3.57 -UCX_TEST_DECLARE(test_ucx_dlist_contains);
    3.58 -UCX_TEST_DECLARE(test_ucx_dlist_remove);
    3.59 -UCX_TEST_DECLARE(test_ucx_dlist_clone);
    3.60 -UCX_TEST_DECLARE(test_ucx_dlist_sort);
    3.61 -
    3.62 -#ifdef	__cplusplus
    3.63 -}
    3.64 -#endif
    3.65 -
    3.66 -#endif	/* DLIST_TESTS_H */
    3.67 -
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/list_tests.c	Mon Jul 22 11:53:39 2013 +0200
     4.3 @@ -0,0 +1,247 @@
     4.4 +/*
     4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6 + *
     4.7 + * Copyright 2013 Olaf Wintermann. All rights reserved.
     4.8 + *
     4.9 + * Redistribution and use in source and binary forms, with or without
    4.10 + * modification, are permitted provided that the following conditions are met:
    4.11 + *
    4.12 + *   1. Redistributions of source code must retain the above copyright
    4.13 + *      notice, this list of conditions and the following disclaimer.
    4.14 + *
    4.15 + *   2. Redistributions in binary form must reproduce the above copyright
    4.16 + *      notice, this list of conditions and the following disclaimer in the
    4.17 + *      documentation and/or other materials provided with the distribution.
    4.18 + *
    4.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    4.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    4.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    4.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    4.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    4.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    4.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    4.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    4.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    4.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    4.29 + * POSSIBILITY OF SUCH DAMAGE.
    4.30 + */
    4.31 +
    4.32 +#include "list_tests.h"
    4.33 +#include "ucx/utils.h"
    4.34 +
    4.35 +UCX_TEST_IMPLEMENT(test_ucx_list_append) {
    4.36 +    UcxList *list = ucx_list_append(NULL, (void*)"Hello");
    4.37 +    UCX_TEST_BEGIN
    4.38 +    
    4.39 +    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    4.40 +            "failed");
    4.41 +    
    4.42 +    list = ucx_list_append(list, (void*)" World!");
    4.43 +    
    4.44 +    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    4.45 +            "failed");
    4.46 +    UCX_TEST_ASSERT(list->next->next == NULL, "failed");
    4.47 +    UCX_TEST_END
    4.48 +    
    4.49 +    ucx_list_free(list);
    4.50 +}
    4.51 +
    4.52 +UCX_TEST_IMPLEMENT(test_ucx_list_prepend) {
    4.53 +    UcxList *list = ucx_list_prepend(NULL, (void*)" World!");
    4.54 +    UCX_TEST_BEGIN
    4.55 +
    4.56 +    list = ucx_list_prepend(list, (void*)"Hello");
    4.57 +    
    4.58 +    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    4.59 +            "failed");
    4.60 +    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    4.61 +            "failed");
    4.62 +    UCX_TEST_ASSERT(list->next->next == NULL, "failed");
    4.63 +    
    4.64 +    UCX_TEST_END
    4.65 +    ucx_list_free(list);
    4.66 +}
    4.67 +
    4.68 +UCX_TEST_IMPLEMENT(test_ucx_list_equals) {
    4.69 +    UcxList *list = ucx_list_append(NULL, (void*)"Hello");
    4.70 +    list = ucx_list_append(list, (void*)" World!");
    4.71 +    UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!");
    4.72 +    list2 = ucx_list_prepend(list2, (void*)"Hello");
    4.73 +    UcxList *list3 = ucx_list_prepend(NULL, (void*)" Welt!");
    4.74 +    list3 = ucx_list_prepend(list3, (void*)"Hallo");
    4.75 +    UCX_TEST_BEGIN
    4.76 +    
    4.77 +    UCX_TEST_ASSERT(ucx_list_equals(list, list2, ucx_strcmp, NULL), "failed");
    4.78 +    UCX_TEST_ASSERT(!ucx_list_equals(list, list3, ucx_strcmp, NULL), "failed");
    4.79 +    
    4.80 +    UCX_TEST_END
    4.81 +    ucx_list_free(list3);
    4.82 +    ucx_list_free(list2);
    4.83 +    ucx_list_free(list);
    4.84 +}
    4.85 +
    4.86 +UCX_TEST_IMPLEMENT(test_ucx_list_concat) {
    4.87 +    UcxList *list = ucx_list_append(NULL, (void*)"Hello");
    4.88 +    UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!");
    4.89 +    UCX_TEST_BEGIN
    4.90 +    
    4.91 +    list = ucx_list_concat(list, list2);
    4.92 +    
    4.93 +    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    4.94 +            "failed");
    4.95 +    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    4.96 +            "failed");
    4.97 +    UCX_TEST_ASSERT(list->next->next == NULL, "failed");
    4.98 +    
    4.99 +    UCX_TEST_END
   4.100 +    ucx_list_free(list);
   4.101 +}
   4.102 +
   4.103 +UCX_TEST_IMPLEMENT(test_ucx_list_size) {
   4.104 +    UcxList *list = ucx_list_append(NULL, (void*)"This ");
   4.105 +    UCX_TEST_BEGIN
   4.106 +    list = ucx_list_append(list, (void*)"list ");
   4.107 +    list = ucx_list_append(list, (void*)"has ");
   4.108 +    list = ucx_list_append(list, (void*)"size ");
   4.109 +    list = ucx_list_append(list, (void*)"5!");
   4.110 +    
   4.111 +    UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed");
   4.112 +    
   4.113 +    UCX_TEST_END
   4.114 +    ucx_list_free(list);
   4.115 +}
   4.116 +
   4.117 +UCX_TEST_IMPLEMENT(test_ucx_list_first) {
   4.118 +    UcxList *list = ucx_list_append(NULL, (void*)"Find ");
   4.119 +    UCX_TEST_BEGIN
   4.120 +    list = ucx_list_append(list, (void*)"the ");
   4.121 +    list = ucx_list_append(list, (void*)"first!");
   4.122 +    
   4.123 +    const char* first = (const char*) (ucx_list_first(list)->data);
   4.124 +    
   4.125 +    UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed");
   4.126 +    
   4.127 +    UCX_TEST_END
   4.128 +    ucx_list_free(list);
   4.129 +}
   4.130 +
   4.131 +UCX_TEST_IMPLEMENT(test_ucx_list_last) {
   4.132 +    UcxList *list = ucx_list_append(NULL, (void*)"Find ");
   4.133 +    UCX_TEST_BEGIN
   4.134 +    list = ucx_list_append(list, (void*)"the ");
   4.135 +    list = ucx_list_append(list, (void*)"last!");
   4.136 +    
   4.137 +    const char* last = (const char*) (ucx_list_last(list)->data);
   4.138 +    
   4.139 +    UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed");
   4.140 +    
   4.141 +    UCX_TEST_END
   4.142 +    ucx_list_free(list);
   4.143 +}
   4.144 +
   4.145 +UCX_TEST_IMPLEMENT(test_ucx_list_get) {
   4.146 +    UcxList *list = ucx_list_append(NULL, (void*)"Find ");
   4.147 +    UCX_TEST_BEGIN
   4.148 +    list = ucx_list_append(list, (void*)"the ");
   4.149 +    list = ucx_list_append(list, (void*)"mid!");
   4.150 +    
   4.151 +    const char* mid = (const char*) (ucx_list_get(list, 1)->data);
   4.152 +    
   4.153 +    UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed");
   4.154 +    
   4.155 +    UCX_TEST_END
   4.156 +    ucx_list_free(list);
   4.157 +}
   4.158 +
   4.159 +UCX_TEST_IMPLEMENT(test_ucx_list_contains) {
   4.160 +    UcxList *l = ucx_list_append(NULL, (void*)"Contains ");
   4.161 +    UCX_TEST_BEGIN
   4.162 +    l = ucx_list_append(l, (void*)"a ");
   4.163 +    l = ucx_list_append(l, (void*)"string!");
   4.164 +    
   4.165 +    UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL),"failed");
   4.166 +    UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL),"failed");
   4.167 +    
   4.168 +    UCX_TEST_END
   4.169 +    ucx_list_free(l);
   4.170 +}
   4.171 +
   4.172 +UCX_TEST_IMPLEMENT(test_ucx_list_remove) {
   4.173 +    UcxList *list = ucx_list_append(NULL, (void*)"Hello");
   4.174 +    UCX_TEST_BEGIN
   4.175 +    list = ucx_list_append(list, (void*)" fucking");
   4.176 +    list = ucx_list_append(list, (void*)" World!");
   4.177 +    
   4.178 +    list = ucx_list_remove(list, ucx_list_get(list, 1));
   4.179 +    
   4.180 +    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
   4.181 +            "failed");
   4.182 +    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
   4.183 +            "failed");
   4.184 +    UCX_TEST_ASSERT(list->next->next == NULL, "failed");
   4.185 +    
   4.186 +    UCX_TEST_END
   4.187 +    ucx_list_free(list);
   4.188 +}
   4.189 +
   4.190 +UCX_TEST_IMPLEMENT(test_ucx_list_clone) {
   4.191 +   
   4.192 +    char *hello = (char*)malloc(6);
   4.193 +    char *world = (char*)malloc(8);
   4.194 +    
   4.195 +    memcpy(hello, "Hello", 6);
   4.196 +    memcpy(world, " World!", 8);
   4.197 +    
   4.198 +    UcxList *list = ucx_list_append(NULL, hello);
   4.199 +    list = ucx_list_append(list, world);
   4.200 +    
   4.201 +    UcxList *copy = ucx_list_clone(list, ucx_strcpy, NULL);
   4.202 +    UCX_TEST_BEGIN
   4.203 +
   4.204 +    UCX_TEST_ASSERT(ucx_list_equals(list, copy, ucx_strcmp, NULL), "failed");
   4.205 +    UCX_TEST_ASSERT(hello != copy->data, "first element is no copy");
   4.206 +    UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy");
   4.207 +
   4.208 +    UCX_TEST_END
   4.209 +    free(copy->next->data);
   4.210 +    free(copy->data);
   4.211 +
   4.212 +    free(world);
   4.213 +    free(hello);
   4.214 +    ucx_list_free(list);
   4.215 +    ucx_list_free(copy);
   4.216 +}
   4.217 +
   4.218 +UCX_TEST_IMPLEMENT(test_ucx_list_sort) {
   4.219 +    UcxList *list = ucx_list_append(NULL, (void*)"this");
   4.220 +    list = ucx_list_append(list, (void*)"is");
   4.221 +    list = ucx_list_append(list, (void*)"a");
   4.222 +    list = ucx_list_append(list, (void*)"test");
   4.223 +    list = ucx_list_append(list, (void*)"for");
   4.224 +    list = ucx_list_append(list, (void*)"partial");
   4.225 +    list = ucx_list_append(list, (void*)"correctness");
   4.226 +
   4.227 +    UcxList *expected = ucx_list_append(NULL, (void*)"a");
   4.228 +    expected = ucx_list_append(expected, (void*)"correctness");
   4.229 +    expected = ucx_list_append(expected, (void*)"for");
   4.230 +    expected = ucx_list_append(expected, (void*)"is");
   4.231 +    expected = ucx_list_append(expected, (void*)"partial");
   4.232 +    expected = ucx_list_append(expected, (void*)"test");
   4.233 +    expected = ucx_list_append(expected, (void*)"this");
   4.234 +
   4.235 +    list = ucx_list_sort(list, ucx_strcmp, NULL);
   4.236 +
   4.237 +    UCX_TEST_BEGIN
   4.238 +    UCX_TEST_ASSERT(
   4.239 +            ucx_list_equals(list, expected, ucx_strcmp, NULL), "failed");
   4.240 +    UcxList *l = list;
   4.241 +    UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null");
   4.242 +    while (l->next != NULL) {
   4.243 +        UCX_TEST_ASSERT(l->next->prev == l, "prev pointer corrupted");
   4.244 +        l = l->next;
   4.245 +    }
   4.246 +    UCX_TEST_END
   4.247 +
   4.248 +    ucx_list_free(expected);
   4.249 +    ucx_list_free(list);
   4.250 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/list_tests.h	Mon Jul 22 11:53:39 2013 +0200
     5.3 @@ -0,0 +1,64 @@
     5.4 +/*
     5.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.6 + *
     5.7 + * Copyright 2013 Olaf Wintermann. All rights reserved.
     5.8 + *
     5.9 + * Redistribution and use in source and binary forms, with or without
    5.10 + * modification, are permitted provided that the following conditions are met:
    5.11 + *
    5.12 + *   1. Redistributions of source code must retain the above copyright
    5.13 + *      notice, this list of conditions and the following disclaimer.
    5.14 + *
    5.15 + *   2. Redistributions in binary form must reproduce the above copyright
    5.16 + *      notice, this list of conditions and the following disclaimer in the
    5.17 + *      documentation and/or other materials provided with the distribution.
    5.18 + *
    5.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    5.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    5.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    5.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    5.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    5.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    5.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    5.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    5.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    5.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    5.29 + * POSSIBILITY OF SUCH DAMAGE.
    5.30 + */
    5.31 +
    5.32 +#ifndef LIST_TESTS_H
    5.33 +#define	LIST_TESTS_H
    5.34 +
    5.35 +#include "main.h"
    5.36 +
    5.37 +#include "ucx/list.h"
    5.38 +#include "ucx/test.h"
    5.39 +
    5.40 +#ifdef	__cplusplus
    5.41 +extern "C" {
    5.42 +#endif
    5.43 +
    5.44 +/*
    5.45 + * Assumed to be correct:
    5.46 + *   ucx_list_free
    5.47 + */
    5.48 +
    5.49 +UCX_TEST_DECLARE(test_ucx_list_append);
    5.50 +UCX_TEST_DECLARE(test_ucx_list_prepend);
    5.51 +UCX_TEST_DECLARE(test_ucx_list_equals);
    5.52 +UCX_TEST_DECLARE(test_ucx_list_concat);
    5.53 +UCX_TEST_DECLARE(test_ucx_list_size);
    5.54 +UCX_TEST_DECLARE(test_ucx_list_first);
    5.55 +UCX_TEST_DECLARE(test_ucx_list_last);
    5.56 +UCX_TEST_DECLARE(test_ucx_list_get);
    5.57 +UCX_TEST_DECLARE(test_ucx_list_contains);
    5.58 +UCX_TEST_DECLARE(test_ucx_list_remove);
    5.59 +UCX_TEST_DECLARE(test_ucx_list_clone);
    5.60 +UCX_TEST_DECLARE(test_ucx_list_sort);
    5.61 +
    5.62 +#ifdef	__cplusplus
    5.63 +}
    5.64 +#endif
    5.65 +
    5.66 +#endif	/* LIST_TESTS_H */
    5.67 +
     6.1 --- a/test/main.c	Mon Jul 22 11:39:06 2013 +0200
     6.2 +++ b/test/main.c	Mon Jul 22 11:53:39 2013 +0200
     6.3 @@ -34,7 +34,7 @@
     6.4  #include "main.h"
     6.5  
     6.6  #include "logging_tests.h"
     6.7 -#include "dlist_tests.h"
     6.8 +#include "list_tests.h"
     6.9  #include "string_tests.h"
    6.10  #include "mpool_tests.h"
    6.11  #include "map_tests.h"
    6.12 @@ -121,18 +121,18 @@
    6.13          ucx_test_register(suite, test_ucx_logger_log);
    6.14          
    6.15          /* UcxDlist Tests */
    6.16 -        ucx_test_register(suite, test_ucx_dlist_append);
    6.17 -        ucx_test_register(suite, test_ucx_dlist_prepend);
    6.18 -        ucx_test_register(suite, test_ucx_dlist_equals);
    6.19 -        ucx_test_register(suite, test_ucx_dlist_concat);
    6.20 -        ucx_test_register(suite, test_ucx_dlist_size);
    6.21 -        ucx_test_register(suite, test_ucx_dlist_first);
    6.22 -        ucx_test_register(suite, test_ucx_dlist_last);
    6.23 -        ucx_test_register(suite, test_ucx_dlist_get);
    6.24 -        ucx_test_register(suite, test_ucx_dlist_contains);
    6.25 -        ucx_test_register(suite, test_ucx_dlist_remove);
    6.26 -        ucx_test_register(suite, test_ucx_dlist_clone);
    6.27 -        ucx_test_register(suite, test_ucx_dlist_sort);
    6.28 +        ucx_test_register(suite, test_ucx_list_append);
    6.29 +        ucx_test_register(suite, test_ucx_list_prepend);
    6.30 +        ucx_test_register(suite, test_ucx_list_equals);
    6.31 +        ucx_test_register(suite, test_ucx_list_concat);
    6.32 +        ucx_test_register(suite, test_ucx_list_size);
    6.33 +        ucx_test_register(suite, test_ucx_list_first);
    6.34 +        ucx_test_register(suite, test_ucx_list_last);
    6.35 +        ucx_test_register(suite, test_ucx_list_get);
    6.36 +        ucx_test_register(suite, test_ucx_list_contains);
    6.37 +        ucx_test_register(suite, test_ucx_list_remove);
    6.38 +        ucx_test_register(suite, test_ucx_list_clone);
    6.39 +        ucx_test_register(suite, test_ucx_list_sort);
    6.40  
    6.41          /* UcxMemPool Tests */
    6.42          ucx_test_register(suite, test_ucx_mempool_new);
     7.1 --- a/ucx/Makefile	Mon Jul 22 11:39:06 2013 +0200
     7.2 +++ b/ucx/Makefile	Mon Jul 22 11:53:39 2013 +0200
     7.3 @@ -30,7 +30,7 @@
     7.4  
     7.5  # list of source files
     7.6  SRC  = utils.c
     7.7 -SRC += dlist.c
     7.8 +SRC += list.c
     7.9  SRC += map.c
    7.10  SRC += properties.c
    7.11  SRC += mempool.c
     8.1 --- a/ucx/dlist.c	Mon Jul 22 11:39:06 2013 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,270 +0,0 @@
     8.4 -/*
     8.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     8.6 - *
     8.7 - * Copyright 2013 Olaf Wintermann. All rights reserved.
     8.8 - *
     8.9 - * Redistribution and use in source and binary forms, with or without
    8.10 - * modification, are permitted provided that the following conditions are met:
    8.11 - *
    8.12 - *   1. Redistributions of source code must retain the above copyright
    8.13 - *      notice, this list of conditions and the following disclaimer.
    8.14 - *
    8.15 - *   2. Redistributions in binary form must reproduce the above copyright
    8.16 - *      notice, this list of conditions and the following disclaimer in the
    8.17 - *      documentation and/or other materials provided with the distribution.
    8.18 - *
    8.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    8.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    8.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    8.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    8.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    8.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    8.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    8.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    8.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    8.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    8.29 - * POSSIBILITY OF SUCH DAMAGE.
    8.30 - */
    8.31 -
    8.32 -#include "dlist.h"
    8.33 -
    8.34 -UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) {
    8.35 -    UcxDlist *ret = NULL;
    8.36 -    while (l != NULL) {
    8.37 -        if (fnc != NULL) {
    8.38 -            ret = ucx_dlist_append(ret, fnc(l->data, data));
    8.39 -        } else {
    8.40 -            ret = ucx_dlist_append(ret, l->data);
    8.41 -        }
    8.42 -        l = l->next;
    8.43 -    }
    8.44 -    return ret;
    8.45 -}
    8.46 -
    8.47 -int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2,
    8.48 -        cmp_func fnc, void* data) {
    8.49 -    if (l1 == l2) return 1;
    8.50 -    
    8.51 -    while (l1 != NULL && l2 != NULL) {
    8.52 -        if (fnc == NULL) {
    8.53 -            if (l1->data != l2->data) return 0;
    8.54 -        } else {
    8.55 -            if (fnc(l1->data, l2->data, data) != 0) return 0;
    8.56 -        }
    8.57 -        l1 = l1->next;
    8.58 -        l2 = l2->next;
    8.59 -    }
    8.60 -    
    8.61 -    return (l1 == NULL && l2 == NULL);
    8.62 -}
    8.63 -
    8.64 -void ucx_dlist_free(UcxDlist *l) {
    8.65 -    UcxDlist *e = l, *f;
    8.66 -    while (e != NULL) {
    8.67 -        f = e;
    8.68 -        e = e->next;
    8.69 -        free(f);
    8.70 -    }
    8.71 -}
    8.72 -
    8.73 -UcxDlist *ucx_dlist_append(UcxDlist *l, void *data)  {
    8.74 -    UcxDlist *nl = (UcxDlist*) malloc(sizeof(UcxDlist));
    8.75 -    if (nl == NULL) return NULL;
    8.76 -    
    8.77 -    nl->data = data;
    8.78 -    nl->next = NULL;
    8.79 -    if (l == NULL) {
    8.80 -        nl->prev = NULL;
    8.81 -        return nl;
    8.82 -    } else {
    8.83 -        UcxDlist *t = ucx_dlist_last(l);
    8.84 -        t->next = nl;
    8.85 -        nl->prev = t;
    8.86 -        return l;
    8.87 -    }
    8.88 -}
    8.89 -
    8.90 -UcxDlist *ucx_dlist_prepend(UcxDlist *l, void *data) {
    8.91 -    UcxDlist *nl = ucx_dlist_append(NULL, data);
    8.92 -    if (nl == NULL) return NULL;
    8.93 -    
    8.94 -    if (l != NULL) {
    8.95 -        nl->next = l;
    8.96 -        l->prev = nl;
    8.97 -    }
    8.98 -    return nl;
    8.99 -}
   8.100 -
   8.101 -UcxDlist *ucx_dlist_concat(UcxDlist *l1, UcxDlist *l2) {
   8.102 -    if (l1 == NULL) {
   8.103 -        return l2;
   8.104 -    } else {
   8.105 -        UcxDlist *last = ucx_dlist_last(l1);
   8.106 -        last->next = l2;
   8.107 -        l2->prev = last;
   8.108 -        return l1;
   8.109 -    }
   8.110 -}
   8.111 -
   8.112 -UcxDlist *ucx_dlist_last(const UcxDlist *l) {
   8.113 -    if (l == NULL) return NULL;
   8.114 -    
   8.115 -    const UcxDlist *e = l;
   8.116 -    while (e->next != NULL) {
   8.117 -        e = e->next;
   8.118 -    }
   8.119 -    return (UcxDlist*)e;
   8.120 -}
   8.121 -
   8.122 -UcxDlist *ucx_dlist_get(const UcxDlist *l, int index) {
   8.123 -    if (l == NULL) return NULL;
   8.124 -
   8.125 -    const UcxDlist *e = l;
   8.126 -    while (e->next != NULL && index > 0) {
   8.127 -        e = e->next;
   8.128 -        index--;
   8.129 -    }
   8.130 -    
   8.131 -    return (UcxDlist*)(index == 0 ? e : NULL);
   8.132 -}
   8.133 -
   8.134 -int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata) {
   8.135 -    UCX_FOREACH(l, e) {
   8.136 -        if (!fnc(elem, e->data, cmpdata)) {
   8.137 -            return 1;
   8.138 -        }
   8.139 -    }
   8.140 -    return 0;
   8.141 -}
   8.142 -
   8.143 -size_t ucx_dlist_size(const UcxDlist *l) {
   8.144 -    if (l == NULL) return 0;
   8.145 -    
   8.146 -    const UcxDlist *e = l;
   8.147 -    size_t s = 1;
   8.148 -    while (e->next != NULL) {
   8.149 -        e = e->next;
   8.150 -        s++;
   8.151 -    }
   8.152 -
   8.153 -    return s;
   8.154 -}
   8.155 -
   8.156 -UcxDlist *ucx_dlist_sort_merge(int length,
   8.157 -        UcxDlist* restrict ls, UcxDlist* restrict le, UcxDlist* restrict re,
   8.158 -        cmp_func fnc, void* data) {
   8.159 -
   8.160 -    UcxDlist** sorted = (UcxDlist**) malloc(sizeof(UcxDlist*)*length);
   8.161 -    UcxDlist *rc, *lc;
   8.162 -
   8.163 -    lc = ls; rc = le;
   8.164 -    int n = 0;
   8.165 -    while (lc && lc != le && rc != re) {
   8.166 -        if (fnc(lc->data, rc->data, data) <= 0) {
   8.167 -            sorted[n] = lc;
   8.168 -            lc = lc->next;
   8.169 -        } else {
   8.170 -            sorted[n] = rc;
   8.171 -            rc = rc->next;
   8.172 -        }
   8.173 -        n++;
   8.174 -    }
   8.175 -    while (lc && lc != le) {
   8.176 -        sorted[n] = lc;
   8.177 -        lc = lc->next;
   8.178 -        n++;
   8.179 -    }
   8.180 -    while (rc && rc != re) {
   8.181 -        sorted[n] = rc;
   8.182 -        rc = rc->next;
   8.183 -        n++;
   8.184 -    }
   8.185 -
   8.186 -    // Update pointer
   8.187 -    sorted[0]->prev = NULL;
   8.188 -    for (int i = 0 ; i < length-1 ; i++) {
   8.189 -        sorted[i]->next = sorted[i+1];
   8.190 -        sorted[i+1]->prev = sorted[i];
   8.191 -    }
   8.192 -    sorted[length-1]->next = NULL;
   8.193 -
   8.194 -    UcxDlist *ret = sorted[0];
   8.195 -    free(sorted);
   8.196 -    return ret;
   8.197 -}
   8.198 -
   8.199 -UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data) {
   8.200 -    if (l == NULL) {
   8.201 -        return NULL;
   8.202 -    }
   8.203 -
   8.204 -    UcxDlist *lc;
   8.205 -    int ln = 1;
   8.206 -
   8.207 -    UcxDlist *restrict ls = l, *restrict le, *restrict re;
   8.208 -    lc = ls;
   8.209 -    while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) {
   8.210 -        lc = lc->next;
   8.211 -        ln++;
   8.212 -    }
   8.213 -    le = lc->next;
   8.214 -
   8.215 -    if (le == NULL) {
   8.216 -        return l; // this list is already sorted :)
   8.217 -    } else {
   8.218 -        UcxDlist *rc;
   8.219 -        int rn = 1;
   8.220 -        rc = le;
   8.221 -        while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) {
   8.222 -            rc = rc->next;
   8.223 -            rn++;
   8.224 -        }
   8.225 -        re = rc->next;
   8.226 -
   8.227 -        // Something left? Sort it!
   8.228 -        UcxDlist *remainder = re;
   8.229 -        size_t remainder_length = ucx_dlist_size(remainder);
   8.230 -        if (remainder != NULL) {
   8.231 -            remainder = ucx_dlist_sort(remainder, fnc, data);
   8.232 -        }
   8.233 -
   8.234 -        // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them
   8.235 -        UcxDlist *sorted = ucx_dlist_sort_merge(ln+rn,
   8.236 -                ls, le, re,
   8.237 -                fnc, data);
   8.238 -
   8.239 -        // merge sorted list with (also sorted) remainder
   8.240 -        l = ucx_dlist_sort_merge(ln+rn+remainder_length,
   8.241 -                sorted, remainder, NULL, fnc, data);
   8.242 -
   8.243 -        return l;
   8.244 -    }
   8.245 -}
   8.246 -
   8.247 -/* dlist specific functions */
   8.248 -UcxDlist *ucx_dlist_first(const UcxDlist *l) {
   8.249 -    if (l == NULL) return NULL;
   8.250 -    
   8.251 -    const UcxDlist *e = l;
   8.252 -    while (e->prev != NULL) {
   8.253 -        e = e->prev;
   8.254 -    }
   8.255 -    return (UcxDlist *)e;
   8.256 -}
   8.257 -
   8.258 -UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) {
   8.259 -    if (e->prev == NULL) {
   8.260 -        if(e->next != NULL) {
   8.261 -            e->next->prev = NULL;
   8.262 -            l = e->next;
   8.263 -        } else {
   8.264 -            l = NULL;
   8.265 -        }
   8.266 -        
   8.267 -    } else {
   8.268 -        e->prev->next = e->next;
   8.269 -        e->next->prev = e->prev;
   8.270 -    }
   8.271 -    free(e);
   8.272 -    return l;
   8.273 -}
     9.1 --- a/ucx/dlist.h	Mon Jul 22 11:39:06 2013 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,86 +0,0 @@
     9.4 -/*
     9.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     9.6 - *
     9.7 - * Copyright 2013 Olaf Wintermann. All rights reserved.
     9.8 - *
     9.9 - * Redistribution and use in source and binary forms, with or without
    9.10 - * modification, are permitted provided that the following conditions are met:
    9.11 - *
    9.12 - *   1. Redistributions of source code must retain the above copyright
    9.13 - *      notice, this list of conditions and the following disclaimer.
    9.14 - *
    9.15 - *   2. Redistributions in binary form must reproduce the above copyright
    9.16 - *      notice, this list of conditions and the following disclaimer in the
    9.17 - *      documentation and/or other materials provided with the distribution.
    9.18 - *
    9.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    9.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    9.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    9.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    9.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    9.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    9.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    9.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    9.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    9.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    9.29 - * POSSIBILITY OF SUCH DAMAGE.
    9.30 - */
    9.31 -
    9.32 -#ifndef UCX_DLIST_H
    9.33 -#define	UCX_DLIST_H
    9.34 -
    9.35 -#include "ucx.h"
    9.36 -#include <stddef.h>
    9.37 -
    9.38 -#ifdef	__cplusplus
    9.39 -extern "C" {
    9.40 -#endif
    9.41 -
    9.42 -/**
    9.43 - * Loop statement for UCX lists.
    9.44 - * 
    9.45 - * The first argument is a pointer to the list. In most cases this will be the
    9.46 - * pointer to the first element of the list, but it may also be an arbitrary
    9.47 - * element of the list. The iteration will then start with that element.
    9.48 - * 
    9.49 - * The second argument is the name of the iteration variable. The scope of
    9.50 - * this variable is limited to the <code>UCX_FOREACH</code> statement.
    9.51 - * 
    9.52 - * @param list The first element of the list
    9.53 - * @param elem The variable name of the element
    9.54 - */
    9.55 -#define UCX_FOREACH(list,elem) \
    9.56 -        for (UcxDlist* elem = list ; elem != NULL ; elem = elem->next)
    9.57 -
    9.58 -typedef struct UcxDlist UcxDlist;
    9.59 -struct UcxDlist {
    9.60 -    void     *data;
    9.61 -    UcxDlist *next;
    9.62 -    UcxDlist *prev;
    9.63 -};
    9.64 -
    9.65 -UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void* data);
    9.66 -int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2,
    9.67 -        cmp_func fnc, void* data);
    9.68 -
    9.69 -void ucx_dlist_free(UcxDlist *l);
    9.70 -UcxDlist *ucx_dlist_append(UcxDlist *l, void *data);
    9.71 -UcxDlist *ucx_dlist_prepend(UcxDlist *l, void *data);
    9.72 -UcxDlist *ucx_dlist_concat(UcxDlist *l1, UcxDlist *l2);
    9.73 -UcxDlist *ucx_dlist_last(const UcxDlist *l);
    9.74 -UcxDlist *ucx_dlist_get(const UcxDlist *l, int index);
    9.75 -size_t ucx_dlist_size(const UcxDlist *l);
    9.76 -int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata);
    9.77 -
    9.78 -UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data);
    9.79 -
    9.80 -/* dlist specific functions */
    9.81 -UcxDlist *ucx_dlist_first(const UcxDlist *l);
    9.82 -UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e);
    9.83 -
    9.84 -#ifdef	__cplusplus
    9.85 -}
    9.86 -#endif
    9.87 -
    9.88 -#endif	/* UCX_DLIST_H */
    9.89 -
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/ucx/list.c	Mon Jul 22 11:53:39 2013 +0200
    10.3 @@ -0,0 +1,269 @@
    10.4 +/*
    10.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    10.6 + *
    10.7 + * Copyright 2013 Olaf Wintermann. All rights reserved.
    10.8 + *
    10.9 + * Redistribution and use in source and binary forms, with or without
   10.10 + * modification, are permitted provided that the following conditions are met:
   10.11 + *
   10.12 + *   1. Redistributions of source code must retain the above copyright
   10.13 + *      notice, this list of conditions and the following disclaimer.
   10.14 + *
   10.15 + *   2. Redistributions in binary form must reproduce the above copyright
   10.16 + *      notice, this list of conditions and the following disclaimer in the
   10.17 + *      documentation and/or other materials provided with the distribution.
   10.18 + *
   10.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   10.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   10.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   10.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
   10.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   10.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   10.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   10.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   10.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   10.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   10.29 + * POSSIBILITY OF SUCH DAMAGE.
   10.30 + */
   10.31 +
   10.32 +#include "list.h"
   10.33 +
   10.34 +UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) {
   10.35 +    UcxList *ret = NULL;
   10.36 +    while (l != NULL) {
   10.37 +        if (fnc != NULL) {
   10.38 +            ret = ucx_list_append(ret, fnc(l->data, data));
   10.39 +        } else {
   10.40 +            ret = ucx_list_append(ret, l->data);
   10.41 +        }
   10.42 +        l = l->next;
   10.43 +    }
   10.44 +    return ret;
   10.45 +}
   10.46 +
   10.47 +int ucx_list_equals(const UcxList *l1, const UcxList *l2,
   10.48 +        cmp_func fnc, void* data) {
   10.49 +    if (l1 == l2) return 1;
   10.50 +    
   10.51 +    while (l1 != NULL && l2 != NULL) {
   10.52 +        if (fnc == NULL) {
   10.53 +            if (l1->data != l2->data) return 0;
   10.54 +        } else {
   10.55 +            if (fnc(l1->data, l2->data, data) != 0) return 0;
   10.56 +        }
   10.57 +        l1 = l1->next;
   10.58 +        l2 = l2->next;
   10.59 +    }
   10.60 +    
   10.61 +    return (l1 == NULL && l2 == NULL);
   10.62 +}
   10.63 +
   10.64 +void ucx_list_free(UcxList *l) {
   10.65 +    UcxList *e = l, *f;
   10.66 +    while (e != NULL) {
   10.67 +        f = e;
   10.68 +        e = e->next;
   10.69 +        free(f);
   10.70 +    }
   10.71 +}
   10.72 +
   10.73 +UcxList *ucx_list_append(UcxList *l, void *data)  {
   10.74 +    UcxList *nl = (UcxList*) malloc(sizeof(UcxList));
   10.75 +    if (nl == NULL) return NULL;
   10.76 +    
   10.77 +    nl->data = data;
   10.78 +    nl->next = NULL;
   10.79 +    if (l == NULL) {
   10.80 +        nl->prev = NULL;
   10.81 +        return nl;
   10.82 +    } else {
   10.83 +        UcxList *t = ucx_list_last(l);
   10.84 +        t->next = nl;
   10.85 +        nl->prev = t;
   10.86 +        return l;
   10.87 +    }
   10.88 +}
   10.89 +
   10.90 +UcxList *ucx_list_prepend(UcxList *l, void *data) {
   10.91 +    UcxList *nl = ucx_list_append(NULL, data);
   10.92 +    if (nl == NULL) return NULL;
   10.93 +    
   10.94 +    if (l != NULL) {
   10.95 +        nl->next = l;
   10.96 +        l->prev = nl;
   10.97 +    }
   10.98 +    return nl;
   10.99 +}
  10.100 +
  10.101 +UcxList *ucx_list_concat(UcxList *l1, UcxList *l2) {
  10.102 +    if (l1 == NULL) {
  10.103 +        return l2;
  10.104 +    } else {
  10.105 +        UcxList *last = ucx_list_last(l1);
  10.106 +        last->next = l2;
  10.107 +        l2->prev = last;
  10.108 +        return l1;
  10.109 +    }
  10.110 +}
  10.111 +
  10.112 +UcxList *ucx_list_last(const UcxList *l) {
  10.113 +    if (l == NULL) return NULL;
  10.114 +    
  10.115 +    const UcxList *e = l;
  10.116 +    while (e->next != NULL) {
  10.117 +        e = e->next;
  10.118 +    }
  10.119 +    return (UcxList*)e;
  10.120 +}
  10.121 +
  10.122 +UcxList *ucx_list_get(const UcxList *l, int index) {
  10.123 +    if (l == NULL) return NULL;
  10.124 +
  10.125 +    const UcxList *e = l;
  10.126 +    while (e->next != NULL && index > 0) {
  10.127 +        e = e->next;
  10.128 +        index--;
  10.129 +    }
  10.130 +    
  10.131 +    return (UcxList*)(index == 0 ? e : NULL);
  10.132 +}
  10.133 +
  10.134 +int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) {
  10.135 +    UCX_FOREACH(e, l) {
  10.136 +        if (!fnc(elem, e->data, cmpdata)) {
  10.137 +            return 1;
  10.138 +        }
  10.139 +    }
  10.140 +    return 0;
  10.141 +}
  10.142 +
  10.143 +size_t ucx_list_size(const UcxList *l) {
  10.144 +    if (l == NULL) return 0;
  10.145 +    
  10.146 +    const UcxList *e = l;
  10.147 +    size_t s = 1;
  10.148 +    while (e->next != NULL) {
  10.149 +        e = e->next;
  10.150 +        s++;
  10.151 +    }
  10.152 +
  10.153 +    return s;
  10.154 +}
  10.155 +
  10.156 +UcxList *ucx_list_sort_merge(int length,
  10.157 +        UcxList* restrict ls, UcxList* restrict le, UcxList* restrict re,
  10.158 +        cmp_func fnc, void* data) {
  10.159 +
  10.160 +    UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length);
  10.161 +    UcxList *rc, *lc;
  10.162 +
  10.163 +    lc = ls; rc = le;
  10.164 +    int n = 0;
  10.165 +    while (lc && lc != le && rc != re) {
  10.166 +        if (fnc(lc->data, rc->data, data) <= 0) {
  10.167 +            sorted[n] = lc;
  10.168 +            lc = lc->next;
  10.169 +        } else {
  10.170 +            sorted[n] = rc;
  10.171 +            rc = rc->next;
  10.172 +        }
  10.173 +        n++;
  10.174 +    }
  10.175 +    while (lc && lc != le) {
  10.176 +        sorted[n] = lc;
  10.177 +        lc = lc->next;
  10.178 +        n++;
  10.179 +    }
  10.180 +    while (rc && rc != re) {
  10.181 +        sorted[n] = rc;
  10.182 +        rc = rc->next;
  10.183 +        n++;
  10.184 +    }
  10.185 +
  10.186 +    // Update pointer
  10.187 +    sorted[0]->prev = NULL;
  10.188 +    for (int i = 0 ; i < length-1 ; i++) {
  10.189 +        sorted[i]->next = sorted[i+1];
  10.190 +        sorted[i+1]->prev = sorted[i];
  10.191 +    }
  10.192 +    sorted[length-1]->next = NULL;
  10.193 +
  10.194 +    UcxList *ret = sorted[0];
  10.195 +    free(sorted);
  10.196 +    return ret;
  10.197 +}
  10.198 +
  10.199 +UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data) {
  10.200 +    if (l == NULL) {
  10.201 +        return NULL;
  10.202 +    }
  10.203 +
  10.204 +    UcxList *lc;
  10.205 +    int ln = 1;
  10.206 +
  10.207 +    UcxList *restrict ls = l, *restrict le, *restrict re;
  10.208 +    lc = ls;
  10.209 +    while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) {
  10.210 +        lc = lc->next;
  10.211 +        ln++;
  10.212 +    }
  10.213 +    le = lc->next;
  10.214 +
  10.215 +    if (le == NULL) {
  10.216 +        return l; // this list is already sorted :)
  10.217 +    } else {
  10.218 +        UcxList *rc;
  10.219 +        int rn = 1;
  10.220 +        rc = le;
  10.221 +        while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) {
  10.222 +            rc = rc->next;
  10.223 +            rn++;
  10.224 +        }
  10.225 +        re = rc->next;
  10.226 +
  10.227 +        // Something left? Sort it!
  10.228 +        UcxList *remainder = re;
  10.229 +        size_t remainder_length = ucx_list_size(remainder);
  10.230 +        if (remainder != NULL) {
  10.231 +            remainder = ucx_list_sort(remainder, fnc, data);
  10.232 +        }
  10.233 +
  10.234 +        // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them
  10.235 +        UcxList *sorted = ucx_list_sort_merge(ln+rn,
  10.236 +                ls, le, re,
  10.237 +                fnc, data);
  10.238 +
  10.239 +        // merge sorted list with (also sorted) remainder
  10.240 +        l = ucx_list_sort_merge(ln+rn+remainder_length,
  10.241 +                sorted, remainder, NULL, fnc, data);
  10.242 +
  10.243 +        return l;
  10.244 +    }
  10.245 +}
  10.246 +
  10.247 +UcxList *ucx_list_first(const UcxList *l) {
  10.248 +    if (l == NULL) return NULL;
  10.249 +    
  10.250 +    const UcxList *e = l;
  10.251 +    while (e->prev != NULL) {
  10.252 +        e = e->prev;
  10.253 +    }
  10.254 +    return (UcxList *)e;
  10.255 +}
  10.256 +
  10.257 +UcxList *ucx_list_remove(UcxList *l, UcxList *e) {
  10.258 +    if (e->prev == NULL) {
  10.259 +        if(e->next != NULL) {
  10.260 +            e->next->prev = NULL;
  10.261 +            l = e->next;
  10.262 +        } else {
  10.263 +            l = NULL;
  10.264 +        }
  10.265 +        
  10.266 +    } else {
  10.267 +        e->prev->next = e->next;
  10.268 +        e->next->prev = e->prev;
  10.269 +    }
  10.270 +    free(e);
  10.271 +    return l;
  10.272 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/ucx/list.h	Mon Jul 22 11:53:39 2013 +0200
    11.3 @@ -0,0 +1,85 @@
    11.4 +/*
    11.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    11.6 + *
    11.7 + * Copyright 2013 Olaf Wintermann. All rights reserved.
    11.8 + *
    11.9 + * Redistribution and use in source and binary forms, with or without
   11.10 + * modification, are permitted provided that the following conditions are met:
   11.11 + *
   11.12 + *   1. Redistributions of source code must retain the above copyright
   11.13 + *      notice, this list of conditions and the following disclaimer.
   11.14 + *
   11.15 + *   2. Redistributions in binary form must reproduce the above copyright
   11.16 + *      notice, this list of conditions and the following disclaimer in the
   11.17 + *      documentation and/or other materials provided with the distribution.
   11.18 + *
   11.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   11.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   11.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   11.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
   11.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   11.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   11.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   11.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   11.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   11.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   11.29 + * POSSIBILITY OF SUCH DAMAGE.
   11.30 + */
   11.31 +
   11.32 +#ifndef UCX_LIST_H
   11.33 +#define	UCX_LIST_H
   11.34 +
   11.35 +#include "ucx.h"
   11.36 +#include <stddef.h>
   11.37 +
   11.38 +#ifdef	__cplusplus
   11.39 +extern "C" {
   11.40 +#endif
   11.41 +
   11.42 +/**
   11.43 + * Loop statement for UCX lists.
   11.44 + * 
   11.45 + * The first argument is a pointer to the list. In most cases this will be the
   11.46 + * pointer to the first element of the list, but it may also be an arbitrary
   11.47 + * element of the list. The iteration will then start with that element.
   11.48 + * 
   11.49 + * The second argument is the name of the iteration variable. The scope of
   11.50 + * this variable is limited to the <code>UCX_FOREACH</code> statement.
   11.51 + * 
   11.52 + * @param list The first element of the list
   11.53 + * @param elem The variable name of the element
   11.54 + */
   11.55 +#define UCX_FOREACH(elem,list) \
   11.56 +        for (UcxList* elem = list ; elem != NULL ; elem = elem->next)
   11.57 +
   11.58 +typedef struct UcxList UcxList;
   11.59 +struct UcxList {
   11.60 +    void    *data;
   11.61 +    UcxList *next;
   11.62 +    UcxList *prev;
   11.63 +};
   11.64 +
   11.65 +UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void* data);
   11.66 +int ucx_list_equals(const UcxList *l1, const UcxList *l2,
   11.67 +        cmp_func fnc, void* data);
   11.68 +
   11.69 +void ucx_list_free(UcxList *l);
   11.70 +UcxList *ucx_list_append(UcxList *l, void *data);
   11.71 +UcxList *ucx_list_prepend(UcxList *l, void *data);
   11.72 +UcxList *ucx_list_concat(UcxList *l1, UcxList *l2);
   11.73 +UcxList *ucx_list_last(const UcxList *l);
   11.74 +UcxList *ucx_list_get(const UcxList *l, int index);
   11.75 +size_t ucx_list_size(const UcxList *l);
   11.76 +int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata);
   11.77 +
   11.78 +UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data);
   11.79 +
   11.80 +UcxList *ucx_list_first(const UcxList *l);
   11.81 +UcxList *ucx_list_remove(UcxList *l, UcxList *e);
   11.82 +
   11.83 +#ifdef	__cplusplus
   11.84 +}
   11.85 +#endif
   11.86 +
   11.87 +#endif	/* UCX_LIST_H */
   11.88 +

mercurial