Mon, 22 Jul 2013 11:39:06 +0200
removal of single linked list implemenation - step 1: removal
test/Makefile | 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 | |
ucx/test.c | file | annotate | diff | comparison | revisions | |
ucx/ucx.h | file | annotate | diff | comparison | revisions |
1.1 --- a/test/Makefile Sat Jul 20 11:13:26 2013 +0200 1.2 +++ b/test/Makefile Mon Jul 22 11:39:06 2013 +0200 1.3 @@ -29,7 +29,6 @@ 1.4 include ../$(CONF).mk 1.5 1.6 SRC = main.c 1.7 -SRC += list_tests.c 1.8 SRC += dlist_tests.c 1.9 SRC += mpool_tests.c 1.10 SRC += map_tests.c
2.1 --- a/test/list_tests.c Sat Jul 20 11:13:26 2013 +0200 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,229 +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 "list_tests.h" 2.33 -#include "ucx/utils.h" 2.34 - 2.35 -UCX_TEST_IMPLEMENT(test_ucx_list_append) { 2.36 - UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 2.37 - UCX_TEST_BEGIN 2.38 - UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 2.39 - "failed"); 2.40 - 2.41 - list = ucx_list_append(list, (void*)" World!"); 2.42 - 2.43 - UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, 2.44 - "failed"); 2.45 - UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 2.46 - 2.47 - UCX_TEST_END 2.48 - ucx_list_free(list); 2.49 -} 2.50 - 2.51 -UCX_TEST_IMPLEMENT(test_ucx_list_prepend) { 2.52 - UcxList *list = ucx_list_prepend(NULL, (void*)" World!"); 2.53 - UCX_TEST_BEGIN 2.54 - list = ucx_list_prepend(list, (void*)"Hello"); 2.55 - 2.56 - UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 2.57 - "failed"); 2.58 - UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, 2.59 - "failed"); 2.60 - UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 2.61 - 2.62 - UCX_TEST_END 2.63 - ucx_list_free(list); 2.64 -} 2.65 - 2.66 -UCX_TEST_IMPLEMENT(test_ucx_list_equals) { 2.67 - UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 2.68 - list = ucx_list_append(list, (void*)" World!"); 2.69 - UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!"); 2.70 - list2 = ucx_list_prepend(list2, (void*)"Hello"); 2.71 - UcxList *list3 = ucx_list_prepend(NULL, (void*)" Welt!"); 2.72 - list3 = ucx_list_prepend(list3, (void*)"Hallo"); 2.73 - 2.74 - UCX_TEST_BEGIN 2.75 - UCX_TEST_ASSERT(ucx_list_equals(list, list2, ucx_strcmp, NULL), "failed"); 2.76 - UCX_TEST_ASSERT(!ucx_list_equals(list, list3, ucx_strcmp, NULL), "failed"); 2.77 - UCX_TEST_END 2.78 - 2.79 - ucx_list_free(list3); 2.80 - ucx_list_free(list2); 2.81 - ucx_list_free(list); 2.82 -} 2.83 - 2.84 -UCX_TEST_IMPLEMENT(test_ucx_list_concat) { 2.85 - UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 2.86 - UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!"); 2.87 - 2.88 - list = ucx_list_concat(list, list2); 2.89 - UCX_TEST_BEGIN 2.90 - 2.91 - UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 2.92 - "failed"); 2.93 - UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, 2.94 - "failed"); 2.95 - UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 2.96 - 2.97 - UCX_TEST_END 2.98 - if (list->next == NULL) { 2.99 - ucx_list_free(list2); 2.100 - } 2.101 - ucx_list_free(list); 2.102 -} 2.103 - 2.104 -UCX_TEST_IMPLEMENT(test_ucx_list_size) { 2.105 - UcxList *list = ucx_list_append(NULL, (void*)"This "); 2.106 - UCX_TEST_BEGIN 2.107 - list = ucx_list_append(list, (void*)"list "); 2.108 - list = ucx_list_append(list, (void*)"has "); 2.109 - list = ucx_list_append(list, (void*)"size "); 2.110 - list = ucx_list_append(list, (void*)"5!"); 2.111 - 2.112 - UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed"); 2.113 - 2.114 - UCX_TEST_END 2.115 - ucx_list_free(list); 2.116 -} 2.117 - 2.118 -UCX_TEST_IMPLEMENT(test_ucx_list_last) { 2.119 - UcxList *list = ucx_list_append(NULL, (void*)"Find "); 2.120 - UCX_TEST_BEGIN 2.121 - list = ucx_list_append(list, (void*)"the "); 2.122 - list = ucx_list_append(list, (void*)"last!"); 2.123 - 2.124 - const char* last = (const char*) (ucx_list_last(list)->data); 2.125 - 2.126 - UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); 2.127 - 2.128 - UCX_TEST_END 2.129 - ucx_list_free(list); 2.130 - 2.131 -} 2.132 - 2.133 -UCX_TEST_IMPLEMENT(test_ucx_list_get) { 2.134 - UcxList *list = ucx_list_append(NULL, (void*)"Find "); 2.135 - UCX_TEST_BEGIN 2.136 - list = ucx_list_append(list, (void*)"the "); 2.137 - list = ucx_list_append(list, (void*)"mid!"); 2.138 - 2.139 - const char* mid = (const char*) (ucx_list_get(list, 1)->data); 2.140 - 2.141 - UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); 2.142 - 2.143 - UCX_TEST_END 2.144 - ucx_list_free(list); 2.145 -} 2.146 - 2.147 -UCX_TEST_IMPLEMENT(test_ucx_list_contains) { 2.148 - UcxList *l = ucx_list_append(NULL, (void*)"Contains "); 2.149 - UCX_TEST_BEGIN 2.150 - l = ucx_list_append(l, (void*)"a "); 2.151 - l = ucx_list_append(l, (void*)"string!"); 2.152 - 2.153 - UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL), "failed"); 2.154 - UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL), "failed"); 2.155 - 2.156 - UCX_TEST_END 2.157 - ucx_list_free(l); 2.158 -} 2.159 - 2.160 -UCX_TEST_IMPLEMENT(test_ucx_list_remove) { 2.161 - UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 2.162 - UCX_TEST_BEGIN 2.163 - list = ucx_list_append(list, (void*)" fucking"); 2.164 - list = ucx_list_append(list, (void*)" World!"); 2.165 - 2.166 - list = ucx_list_remove(list, ucx_list_get(list, 1)); 2.167 - 2.168 - UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 2.169 - "failed"); 2.170 - UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, 2.171 - "failed"); 2.172 - UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 2.173 - UCX_TEST_END 2.174 - 2.175 - ucx_list_free(list); 2.176 -} 2.177 - 2.178 -UCX_TEST_IMPLEMENT(test_ucx_list_clone) { 2.179 - 2.180 - char *hello = (char*)malloc(6); 2.181 - char *world = (char*)malloc(8); 2.182 - 2.183 - memcpy(hello, "Hello", 6); 2.184 - memcpy(world, " World!", 8); 2.185 - 2.186 - UcxList *list = ucx_list_append(NULL, hello); 2.187 - list = ucx_list_append(list, world); 2.188 - 2.189 - UcxList *copy = ucx_list_clone(list, ucx_strcpy, NULL); 2.190 - UCX_TEST_BEGIN 2.191 - 2.192 - UCX_TEST_ASSERT(ucx_list_equals(list, copy, ucx_strcmp, NULL), "failed"); 2.193 - UCX_TEST_ASSERT(hello != copy->data, "first element is no copy"); 2.194 - UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy"); 2.195 - 2.196 - UCX_TEST_END 2.197 - free(copy->next->data); 2.198 - free(copy->data); 2.199 - 2.200 - free(world); 2.201 - free(hello); 2.202 - ucx_list_free(list); 2.203 - ucx_list_free(copy); 2.204 -} 2.205 - 2.206 -UCX_TEST_IMPLEMENT(test_ucx_list_sort) { 2.207 - UcxList *list = ucx_list_append(NULL, (void*)"this"); 2.208 - list = ucx_list_append(list, (void*)"is"); 2.209 - list = ucx_list_append(list, (void*)"a"); 2.210 - list = ucx_list_append(list, (void*)"test"); 2.211 - list = ucx_list_append(list, (void*)"for"); 2.212 - list = ucx_list_append(list, (void*)"partial"); 2.213 - list = ucx_list_append(list, (void*)"correctness"); 2.214 - 2.215 - UcxList *expected = ucx_list_append(NULL, (void*)"a"); 2.216 - expected = ucx_list_append(expected, (void*)"correctness"); 2.217 - expected = ucx_list_append(expected, (void*)"for"); 2.218 - expected = ucx_list_append(expected, (void*)"is"); 2.219 - expected = ucx_list_append(expected, (void*)"partial"); 2.220 - expected = ucx_list_append(expected, (void*)"test"); 2.221 - expected = ucx_list_append(expected, (void*)"this"); 2.222 - 2.223 - list = ucx_list_sort(list, ucx_strcmp, NULL); 2.224 - 2.225 - UCX_TEST_BEGIN 2.226 - UCX_TEST_ASSERT( 2.227 - ucx_list_equals(list, expected, ucx_strcmp, NULL), "failed"); 2.228 - UCX_TEST_END 2.229 - 2.230 - ucx_list_free(expected); 2.231 - ucx_list_free(list); 2.232 -}
3.1 --- a/test/list_tests.h Sat Jul 20 11:13:26 2013 +0200 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,63 +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 LIST_TESTS_H 3.33 -#define LIST_TESTS_H 3.34 - 3.35 -#include "main.h" 3.36 - 3.37 -#include "ucx/list.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_list_free 3.47 - */ 3.48 - 3.49 -UCX_TEST_DECLARE(test_ucx_list_append); 3.50 -UCX_TEST_DECLARE(test_ucx_list_prepend); 3.51 -UCX_TEST_DECLARE(test_ucx_list_equals); 3.52 -UCX_TEST_DECLARE(test_ucx_list_concat); 3.53 -UCX_TEST_DECLARE(test_ucx_list_size); 3.54 -UCX_TEST_DECLARE(test_ucx_list_last); 3.55 -UCX_TEST_DECLARE(test_ucx_list_get); 3.56 -UCX_TEST_DECLARE(test_ucx_list_contains); 3.57 -UCX_TEST_DECLARE(test_ucx_list_remove); 3.58 -UCX_TEST_DECLARE(test_ucx_list_clone); 3.59 -UCX_TEST_DECLARE(test_ucx_list_sort); 3.60 - 3.61 -#ifdef __cplusplus 3.62 -} 3.63 -#endif 3.64 - 3.65 -#endif /* LIST_TESTS_H */ 3.66 -
4.1 --- a/test/main.c Sat Jul 20 11:13:26 2013 +0200 4.2 +++ b/test/main.c Mon Jul 22 11:39:06 2013 +0200 4.3 @@ -34,7 +34,6 @@ 4.4 #include "main.h" 4.5 4.6 #include "logging_tests.h" 4.7 -#include "list_tests.h" 4.8 #include "dlist_tests.h" 4.9 #include "string_tests.h" 4.10 #include "mpool_tests.h" 4.11 @@ -120,19 +119,6 @@ 4.12 4.13 /* UcxLogger Tests */ 4.14 ucx_test_register(suite, test_ucx_logger_log); 4.15 - 4.16 - /* UcxList Tests */ 4.17 - ucx_test_register(suite, test_ucx_list_append); 4.18 - ucx_test_register(suite, test_ucx_list_prepend); 4.19 - ucx_test_register(suite, test_ucx_list_equals); 4.20 - ucx_test_register(suite, test_ucx_list_concat); 4.21 - ucx_test_register(suite, test_ucx_list_size); 4.22 - ucx_test_register(suite, test_ucx_list_last); 4.23 - ucx_test_register(suite, test_ucx_list_get); 4.24 - ucx_test_register(suite, test_ucx_list_contains); 4.25 - ucx_test_register(suite, test_ucx_list_remove); 4.26 - ucx_test_register(suite, test_ucx_list_clone); 4.27 - ucx_test_register(suite, test_ucx_list_sort); 4.28 4.29 /* UcxDlist Tests */ 4.30 ucx_test_register(suite, test_ucx_dlist_append);
5.1 --- a/ucx/Makefile Sat Jul 20 11:13:26 2013 +0200 5.2 +++ b/ucx/Makefile Mon Jul 22 11:39:06 2013 +0200 5.3 @@ -30,7 +30,6 @@ 5.4 5.5 # list of source files 5.6 SRC = utils.c 5.7 -SRC += list.c 5.8 SRC += dlist.c 5.9 SRC += map.c 5.10 SRC += properties.c
6.1 --- a/ucx/dlist.c Sat Jul 20 11:13:26 2013 +0200 6.2 +++ b/ucx/dlist.c Mon Jul 22 11:39:06 2013 +0200 6.3 @@ -129,7 +129,7 @@ 6.4 } 6.5 6.6 int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata) { 6.7 - UCX_FOREACH(UcxDlist*, l, e) { 6.8 + UCX_FOREACH(l, e) { 6.9 if (!fnc(elem, e->data, cmpdata)) { 6.10 return 1; 6.11 }
7.1 --- a/ucx/dlist.h Sat Jul 20 11:13:26 2013 +0200 7.2 +++ b/ucx/dlist.h Mon Jul 22 11:39:06 2013 +0200 7.3 @@ -36,6 +36,22 @@ 7.4 extern "C" { 7.5 #endif 7.6 7.7 +/** 7.8 + * Loop statement for UCX lists. 7.9 + * 7.10 + * The first argument is a pointer to the list. In most cases this will be the 7.11 + * pointer to the first element of the list, but it may also be an arbitrary 7.12 + * element of the list. The iteration will then start with that element. 7.13 + * 7.14 + * The second argument is the name of the iteration variable. The scope of 7.15 + * this variable is limited to the <code>UCX_FOREACH</code> statement. 7.16 + * 7.17 + * @param list The first element of the list 7.18 + * @param elem The variable name of the element 7.19 + */ 7.20 +#define UCX_FOREACH(list,elem) \ 7.21 + for (UcxDlist* elem = list ; elem != NULL ; elem = elem->next) 7.22 + 7.23 typedef struct UcxDlist UcxDlist; 7.24 struct UcxDlist { 7.25 void *data;
8.1 --- a/ucx/list.c Sat Jul 20 11:13:26 2013 +0200 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,255 +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 "list.h" 8.33 - 8.34 -UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) { 8.35 - UcxList *ret = NULL; 8.36 - while (l != NULL) { 8.37 - if (fnc != NULL) { 8.38 - ret = ucx_list_append(ret, fnc(l->data, data)); 8.39 - } else { 8.40 - ret = ucx_list_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_list_equals(const UcxList *l1, const UcxList *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_list_free(UcxList *l) { 8.65 - UcxList *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 -UcxList *ucx_list_append(UcxList *l, void *data) { 8.74 - UcxList *nl = (UcxList*) malloc(sizeof(UcxList)); 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 - return nl; 8.81 - } else { 8.82 - UcxList *t = ucx_list_last(l); 8.83 - t->next = nl; 8.84 - return l; 8.85 - } 8.86 -} 8.87 - 8.88 -UcxList *ucx_list_prepend(UcxList *l, void *data) { 8.89 - UcxList *nl = ucx_list_append(NULL, data); 8.90 - if (nl == NULL) return NULL; 8.91 - 8.92 - if (l != NULL) { 8.93 - nl->next = l; 8.94 - } 8.95 - return nl; 8.96 -} 8.97 - 8.98 -UcxList *ucx_list_concat(UcxList *l1, UcxList *l2) { 8.99 - if (l1 == NULL) { 8.100 - return l2; 8.101 - } else { 8.102 - UcxList *last = ucx_list_last(l1); 8.103 - last->next = l2; 8.104 - return l1; 8.105 - } 8.106 -} 8.107 - 8.108 -UcxList *ucx_list_last(const UcxList *l) { 8.109 - if (l == NULL) return NULL; 8.110 - 8.111 - const UcxList *e = l; 8.112 - while (e->next != NULL) { 8.113 - e = e->next; 8.114 - } 8.115 - return (UcxList*)e; 8.116 -} 8.117 - 8.118 -UcxList *ucx_list_get(const UcxList *l, int index) { 8.119 - if (l == NULL) return NULL; 8.120 - 8.121 - const UcxList *e = l; 8.122 - while (e->next != NULL && index > 0) { 8.123 - e = e->next; 8.124 - index--; 8.125 - } 8.126 - 8.127 - return (UcxList*)(index == 0 ? e : NULL); 8.128 -} 8.129 - 8.130 -int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { 8.131 - UCX_FOREACH(UcxList*, l, e) { 8.132 - if (!fnc(elem, e->data, cmpdata)) { 8.133 - return 1; 8.134 - } 8.135 - } 8.136 - return 0; 8.137 -} 8.138 - 8.139 -size_t ucx_list_size(const UcxList *l) { 8.140 - if (l == NULL) return 0; 8.141 - 8.142 - const UcxList *e = l; 8.143 - size_t s = 1; 8.144 - while (e->next != NULL) { 8.145 - e = e->next; 8.146 - s++; 8.147 - } 8.148 - 8.149 - return s; 8.150 -} 8.151 - 8.152 -UcxList *ucx_list_sort_merge(int length, 8.153 - UcxList* restrict ls, UcxList* restrict le, UcxList* restrict re, 8.154 - cmp_func fnc, void* data) { 8.155 - 8.156 - UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length); 8.157 - UcxList *rc, *lc; 8.158 - 8.159 - lc = ls; rc = le; 8.160 - int n = 0; 8.161 - while (lc && lc != le && rc != re) { 8.162 - if (fnc(lc->data, rc->data, data) <= 0) { 8.163 - sorted[n] = lc; 8.164 - lc = lc->next; 8.165 - } else { 8.166 - sorted[n] = rc; 8.167 - rc = rc->next; 8.168 - } 8.169 - n++; 8.170 - } 8.171 - while (lc && lc != le) { 8.172 - sorted[n] = lc; 8.173 - lc = lc->next; 8.174 - n++; 8.175 - } 8.176 - while (rc && rc != re) { 8.177 - sorted[n] = rc; 8.178 - rc = rc->next; 8.179 - n++; 8.180 - } 8.181 - 8.182 - // Update pointer 8.183 - for (int i = 0 ; i < length-1 ; i++) { 8.184 - sorted[i]->next = sorted[i+1]; 8.185 - } 8.186 - sorted[length-1]->next = NULL; 8.187 - 8.188 - UcxList *ret = sorted[0]; 8.189 - free(sorted); 8.190 - return ret; 8.191 -} 8.192 - 8.193 -UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data) { 8.194 - if (l == NULL) { 8.195 - return NULL; 8.196 - } 8.197 - 8.198 - UcxList *lc; 8.199 - int ln = 1; 8.200 - 8.201 - UcxList *restrict ls = l, *restrict le, *restrict re; 8.202 - lc = ls; 8.203 - while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) { 8.204 - lc = lc->next; 8.205 - ln++; 8.206 - } 8.207 - le = lc->next; 8.208 - 8.209 - if (le == NULL) { 8.210 - return l; // this list is already sorted :) 8.211 - } else { 8.212 - UcxList *rc; 8.213 - int rn = 1; 8.214 - rc = le; 8.215 - while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) { 8.216 - rc = rc->next; 8.217 - rn++; 8.218 - } 8.219 - re = rc->next; 8.220 - 8.221 - // Something left? Sort it! 8.222 - UcxList *remainder = re; 8.223 - size_t remainder_length = ucx_list_size(remainder); 8.224 - if (remainder != NULL) { 8.225 - remainder = ucx_list_sort(remainder, fnc, data); 8.226 - } 8.227 - 8.228 - // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them 8.229 - UcxList *sorted = ucx_list_sort_merge(ln+rn, 8.230 - ls, le, re, 8.231 - fnc, data); 8.232 - 8.233 - // merge sorted list with (also sorted) remainder 8.234 - l = ucx_list_sort_merge(ln+rn+remainder_length, 8.235 - sorted, remainder, NULL, fnc, data); 8.236 - 8.237 - return l; 8.238 - } 8.239 -} 8.240 - 8.241 -/* list specific functions */ 8.242 -UcxList *ucx_list_remove(UcxList *l, UcxList *e) { 8.243 - if (e == l) { 8.244 - l = e->next; 8.245 - free(e); 8.246 - } else { 8.247 - UcxList *f = l; 8.248 - while (f->next != NULL && f->next != e) { 8.249 - f = f->next; 8.250 - } 8.251 - /* perform remove if this element is found in this list */ 8.252 - if (f->next == e) { 8.253 - f->next = e->next; 8.254 - free(e); 8.255 - } 8.256 - } 8.257 - return l; 8.258 -}
9.1 --- a/ucx/list.h Sat Jul 20 11:13:26 2013 +0200 9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 9.3 @@ -1,68 +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_LIST_H 9.33 -#define UCX_LIST_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 -typedef struct UcxList UcxList; 9.43 -struct UcxList { 9.44 - void *data; 9.45 - UcxList *next; 9.46 -}; 9.47 - 9.48 -UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data); 9.49 -int ucx_list_equals(const UcxList *l1, const UcxList *l2, 9.50 - cmp_func fnc, void *data); 9.51 - 9.52 -void ucx_list_free(UcxList *l); 9.53 -UcxList *ucx_list_append(UcxList *l, void *data); 9.54 -UcxList *ucx_list_prepend(UcxList *l, void *data); 9.55 -UcxList *ucx_list_concat(UcxList *l1, UcxList *l2); 9.56 -UcxList *ucx_list_last(const UcxList *l); 9.57 -UcxList *ucx_list_get(const UcxList *l, int index); 9.58 -size_t ucx_list_size(const UcxList *l); 9.59 -int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata); 9.60 - 9.61 -UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data); 9.62 - 9.63 -/* list specific functions */ 9.64 -UcxList *ucx_list_remove(UcxList *l, UcxList *e); 9.65 - 9.66 -#ifdef __cplusplus 9.67 -} 9.68 -#endif 9.69 - 9.70 -#endif /* UCX_LIST_H */ 9.71 -
10.1 --- a/ucx/test.c Sat Jul 20 11:13:26 2013 +0200 10.2 +++ b/ucx/test.c Mon Jul 22 11:39:06 2013 +0200 10.3 @@ -81,8 +81,8 @@ 10.4 void ucx_test_run(UcxTestSuite* suite, FILE* output) { 10.5 suite->success = 0; 10.6 suite->failure = 0; 10.7 - UCX_FOREACH (UcxTestList*, suite->tests, e) { 10.8 - e->test(suite, output); 10.9 + for (UcxTestList* elem = suite->tests ; elem ; elem = elem->next) { 10.10 + elem->test(suite, output); 10.11 } 10.12 fwrite("\nAll test completed.\n", 1, 21, output); 10.13 fprintf(output, " Total: %d\n Success: %d\n Failure: %d\n",
11.1 --- a/ucx/ucx.h Sat Jul 20 11:13:26 2013 +0200 11.2 +++ b/ucx/ucx.h Mon Jul 22 11:39:06 2013 +0200 11.3 @@ -47,33 +47,6 @@ 11.4 #endif 11.5 11.6 /** 11.7 - * Generic loop statement for lists. 11.8 - * 11.9 - * The first argument is the type of the list and its elements (e.g. UcxList). 11.10 - * The structure invariant of the list must be as follows: 11.11 - * <ul> 11.12 - * <li>a first (non-<code>NULL</code>) element</li> 11.13 - * <li>for each element a reference to the <code>next</code> element (the 11.14 - * variable name of the pointer MUST be <code>next</code>)</li> 11.15 - * <li>the last element of the list MUST have the <code>next</code> pointer 11.16 - * set to <code>NULL</code></li> 11.17 - * </ul> 11.18 - * 11.19 - * The second argument is a pointer to the list. In most cases this will be the 11.20 - * pointer to the first element of the list, but it may also be an arbitrary 11.21 - * element of the list. The iteration will then start with that element. 11.22 - * 11.23 - * The third argument is the name of the iteration variable. The scope of 11.24 - * this variable is limited to the <code>UCX_FOREACH</code> statement. 11.25 - * 11.26 - * @param type The type of <b>both</b> the list and the element 11.27 - * @param list The first element of the list 11.28 - * @param elem The variable name of the element 11.29 - */ 11.30 -#define UCX_FOREACH(type,list,elem) \ 11.31 - for (type elem = list ; elem != NULL ; elem = elem->next) 11.32 - 11.33 -/** 11.34 * Function pointer to a compare function. 11.35 * 11.36 * The compare function shall take three arguments: the two values that shall be