diff -r 540d99722f1f -r 7fb0f74517c5 ucx/list.c --- a/ucx/list.c Mon Jul 22 11:53:39 2013 +0200 +++ b/ucx/list.c Mon Jul 22 13:45:49 2013 +0200 @@ -116,6 +116,18 @@ return (UcxList*)e; } +ssize_t ucx_list_indexof(const UcxList *list, const UcxList *elem) { + ssize_t index = 0; + while (list) { + if (list == elem) { + return index; + } + list = list->next; + index++; + } + return -1; +} + UcxList *ucx_list_get(const UcxList *l, int index) { if (l == NULL) return NULL; @@ -128,13 +140,19 @@ return (UcxList*)(index == 0 ? e : NULL); } +ssize_t ucx_list_find(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { + ssize_t index = 0; + UCX_FOREACH(e, l) { + if (fnc(elem, e->data, cmpdata) == 0) { + return index; + } + index++; + } + return -1; +} + int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { - UCX_FOREACH(e, l) { - if (!fnc(elem, e->data, cmpdata)) { - return 1; - } - } - return 0; + return ucx_list_find(l, elem, fnc, cmpdata) > -1; } size_t ucx_list_size(const UcxList *l) {