ucx/list.c

changeset 18
69636f81db31
parent 10
df8140ba781c
child 22
76cdd8209f1f
equal deleted inserted replaced
17:2e7050c3a18e 18:69636f81db31
1 #include "list.h" 1 #include "list.h"
2
3 UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) {
4 UcxList *ret = NULL;
5 while (l != NULL) {
6 if (fnc != NULL) {
7 ret = ucx_list_append(ret, fnc(l->data, data));
8 } else {
9 ret = ucx_list_append(ret, l->data);
10 }
11 l = l->next;
12 }
13 return ret;
14 }
15
16 int ucx_list_equals(UcxList *l1, UcxList *l2, cmp_func fnc, void* data) {
17 if (l1 == l2) return 1;
18
19 while (l1 != NULL && l2 != NULL) {
20 if (fnc == NULL) {
21 if (l1->data != l2->data) return 0;
22 } else {
23 if (fnc(l1->data, l2->data, data) != 0) return 0;
24 }
25 l1 = l1->next;
26 l2 = l2->next;
27 }
28
29 return (l1 == NULL && l2 == NULL);
30 }
2 31
3 void ucx_list_free(UcxList *l) { 32 void ucx_list_free(UcxList *l) {
4 UcxList *e = l, *f; 33 UcxList *e = l, *f;
5 while (e != NULL) { 34 while (e != NULL) {
6 f = e; 35 f = e;

mercurial