diff -r b8bf95b39952 -r cff9c4101dd7 src/server/ucx/dlist.c --- a/src/server/ucx/dlist.c Sat Jan 14 13:53:44 2012 +0100 +++ b/src/server/ucx/dlist.c Sat Jan 14 14:33:38 2012 +0100 @@ -1,5 +1,34 @@ #include "dlist.h" +UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) { + UcxDlist *ret = NULL; + while (l != NULL) { + if (fnc != NULL) { + ret = ucx_dlist_append(ret, fnc(l->data, data)); + } else { + ret = ucx_dlist_append(ret, l->data); + } + l = l->next; + } + return ret; +} + +int ucx_dlist_equals(UcxDlist *l1, UcxDlist *l2, cmp_func fnc, void* data) { + if (l1 == l2) return 1; + + while (l1 != NULL && l2 != NULL) { + if (fnc == NULL) { + if (l1->data != l2->data) return 0; + } else { + if (fnc(l1->data, l2->data, data) != 0) return 0; + } + l1 = l1->next; + l2 = l2->next; + } + + return (l1 == NULL && l2 == NULL); +} + void ucx_dlist_free(UcxDlist *l) { UcxDlist *e = l, *f; while (e != NULL) { @@ -12,7 +41,7 @@ UcxDlist *ucx_dlist_append(UcxDlist *l, void *data) { UcxDlist *nl = (UcxDlist*) malloc(sizeof(UcxDlist)); if (nl == NULL) return NULL; - + nl->data = data; nl->next = NULL; if (l == NULL) { @@ -28,7 +57,7 @@ UcxDlist *ucx_dlist_prepend(UcxDlist *l, void *data) { UcxDlist *nl = ucx_dlist_append(NULL, data); if (nl == NULL) return NULL; - + if (l != NULL) { nl->next = l; l->prev = nl; @@ -49,7 +78,7 @@ UcxDlist *ucx_dlist_last(UcxDlist *l) { if (l == NULL) return NULL; - + UcxDlist *e = l; while (e->next != NULL) { e = e->next; @@ -65,13 +94,13 @@ e = e->next; index--; } - + return index == 0 ? e : NULL; } size_t ucx_dlist_size(UcxDlist *l) { if (l == NULL) return 0; - + UcxDlist *e = l; size_t s = 1; while (e->next != NULL) { @@ -93,7 +122,7 @@ /* dlist specific functions */ UcxDlist *ucx_dlist_first(UcxDlist *l) { if (l == NULL) return NULL; - + UcxDlist *e = l; while (e->prev != NULL) { e = e->prev;