Mon, 25 Feb 2013 16:26:50 +0100
some fixes + ucx_(d)list_contains
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/string.c | file | annotate | diff | comparison | revisions |
1.1 --- a/ucx/dlist.c Mon Feb 25 13:25:07 2013 +0100 1.2 +++ b/ucx/dlist.c Mon Feb 25 16:26:50 2013 +0100 1.3 @@ -1,7 +1,6 @@ 1.4 #include "dlist.h" 1.5 1.6 -UcxDlist *restrict ucx_dlist_clone(UcxDlist *restrict l, 1.7 - copy_func fnc, void *data) { 1.8 +UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) { 1.9 UcxDlist *ret = NULL; 1.10 while (l != NULL) { 1.11 if (fnc != NULL) { 1.12 @@ -101,6 +100,15 @@ 1.13 return (UcxDlist*)(index == 0 ? e : NULL); 1.14 } 1.15 1.16 +int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata) { 1.17 + UCX_FOREACH(UcxDlist*, l, e) { 1.18 + if (!fnc(elem, e->data, cmpdata)) { 1.19 + return 1; 1.20 + } 1.21 + } 1.22 + return 0; 1.23 +} 1.24 + 1.25 size_t ucx_dlist_size(const UcxDlist *l) { 1.26 if (l == NULL) return 0; 1.27
2.1 --- a/ucx/dlist.h Mon Feb 25 13:25:07 2013 +0100 2.2 +++ b/ucx/dlist.h Mon Feb 25 16:26:50 2013 +0100 2.3 @@ -19,8 +19,7 @@ 2.4 UcxDlist *restrict prev; 2.5 }; 2.6 2.7 -UcxDlist *restrict ucx_dlist_clone(UcxDlist *restrict l, 2.8 - copy_func fnc, void* data); 2.9 +UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void* data); 2.10 int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2, 2.11 cmp_func fnc, void* data); 2.12 2.13 @@ -31,6 +30,7 @@ 2.14 UcxDlist *ucx_dlist_last(const UcxDlist *l); 2.15 UcxDlist *ucx_dlist_get(const UcxDlist *l, int index); 2.16 size_t ucx_dlist_size(const UcxDlist *l); 2.17 +int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata); 2.18 2.19 UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data); 2.20
3.1 --- a/ucx/list.c Mon Feb 25 13:25:07 2013 +0100 3.2 +++ b/ucx/list.c Mon Feb 25 16:26:50 2013 +0100 3.3 @@ -1,7 +1,6 @@ 3.4 #include "list.h" 3.5 3.6 -UcxList *restrict ucx_list_clone(UcxList *restrict l, 3.7 - copy_func fnc, void *data) { 3.8 +UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) { 3.9 UcxList *ret = NULL; 3.10 while (l != NULL) { 3.11 if (fnc != NULL) { 3.12 @@ -97,6 +96,15 @@ 3.13 return (UcxList*)(index == 0 ? e : NULL); 3.14 } 3.15 3.16 +int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { 3.17 + UCX_FOREACH(UcxList*, l, e) { 3.18 + if (!fnc(elem, e->data, cmpdata)) { 3.19 + return 1; 3.20 + } 3.21 + } 3.22 + return 0; 3.23 +} 3.24 + 3.25 size_t ucx_list_size(const UcxList *l) { 3.26 if (l == NULL) return 0; 3.27
4.1 --- a/ucx/list.h Mon Feb 25 13:25:07 2013 +0100 4.2 +++ b/ucx/list.h Mon Feb 25 16:26:50 2013 +0100 4.3 @@ -18,8 +18,7 @@ 4.4 UcxList *next; 4.5 }; 4.6 4.7 -UcxList *restrict ucx_list_clone(UcxList *restrict l, 4.8 - copy_func fnc, void *data); 4.9 +UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data); 4.10 int ucx_list_equals(const UcxList *l1, const UcxList *l2, 4.11 cmp_func fnc, void *data); 4.12 4.13 @@ -30,6 +29,7 @@ 4.14 UcxList *ucx_list_last(const UcxList *l); 4.15 UcxList *ucx_list_get(const UcxList *l, int index); 4.16 size_t ucx_list_size(const UcxList *l); 4.17 +int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata); 4.18 4.19 UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data); 4.20
5.1 --- a/ucx/string.c Mon Feb 25 13:25:07 2013 +0100 5.2 +++ b/ucx/string.c Mon Feb 25 16:26:50 2013 +0100 5.3 @@ -161,11 +161,13 @@ 5.4 sstr_t sstrdup(sstr_t s) { 5.5 sstr_t newstring; 5.6 newstring.ptr = (char*) malloc(s.length + 1); 5.7 - if (newstring.ptr != NULL) { 5.8 + if (newstring.ptr) { 5.9 newstring.length = s.length; 5.10 newstring.ptr[newstring.length] = 0; 5.11 5.12 memcpy(newstring.ptr, s.ptr, s.length); 5.13 + } else { 5.14 + newstring.length = 0; 5.15 } 5.16 5.17 return newstring;