ucx/dlist.c

changeset 87
bd444539cced
parent 73
f15c7d6aebb9
child 93
a6a99e721660
equal deleted inserted replaced
86:55bf819cbc88 87:bd444539cced
1 #include "dlist.h" 1 #include "dlist.h"
2 2
3 UcxDlist *restrict ucx_dlist_clone(UcxDlist *restrict l, 3 UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) {
4 copy_func fnc, void *data) {
5 UcxDlist *ret = NULL; 4 UcxDlist *ret = NULL;
6 while (l != NULL) { 5 while (l != NULL) {
7 if (fnc != NULL) { 6 if (fnc != NULL) {
8 ret = ucx_dlist_append(ret, fnc(l->data, data)); 7 ret = ucx_dlist_append(ret, fnc(l->data, data));
9 } else { 8 } else {
97 e = e->next; 96 e = e->next;
98 index--; 97 index--;
99 } 98 }
100 99
101 return (UcxDlist*)(index == 0 ? e : NULL); 100 return (UcxDlist*)(index == 0 ? e : NULL);
101 }
102
103 int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata) {
104 UCX_FOREACH(UcxDlist*, l, e) {
105 if (!fnc(elem, e->data, cmpdata)) {
106 return 1;
107 }
108 }
109 return 0;
102 } 110 }
103 111
104 size_t ucx_dlist_size(const UcxDlist *l) { 112 size_t ucx_dlist_size(const UcxDlist *l) {
105 if (l == NULL) return 0; 113 if (l == NULL) return 0;
106 114

mercurial