ucx/list.c

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

mercurial