Mercurial > hg > th-libs
changeset 54:48926b3ff598
Add new linked list handling functions: th_llist_foreach() and th_llist_foreach_cond()
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 26 May 2012 02:25:27 +0300 |
parents | 2c90b33d3617 |
children | 300fba04b7ad |
files | th_util.c th_util.h |
diffstat | 2 files changed, 34 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/th_util.c Sat May 26 01:04:12 2012 +0300 +++ b/th_util.c Sat May 26 02:25:27 2012 +0300 @@ -395,6 +395,37 @@ } +void th_llist_foreach(qlist_t *list, void (*func)(qlist_t *node)) +{ + qlist_t *curr = list; + + while (curr != NULL) + { + func(curr); + curr = curr->next; + } +} + + +qlist_t * th_llist_foreach_cond(qlist_t *list, int (*func)(qlist_t *node), int *ret) +{ + qlist_t *curr = list; + + while (curr != NULL) + { + int res = func(curr); + if (res != 0) + { + *ret = res; + return curr; + } + curr = curr->next; + } + + return NULL; +} + + qlist_t * th_llist_find(qlist_t *list, const void *data) { qlist_t *curr = list;
--- a/th_util.h Sat May 26 01:04:12 2012 +0300 +++ b/th_util.h Sat May 26 02:25:27 2012 +0300 @@ -115,6 +115,9 @@ size_t th_llist_length(const qlist_t *list); ssize_t th_llist_position(const qlist_t *list, const qlist_t *node); +void th_llist_foreach(qlist_t *list, void (*func)(qlist_t *node)); +qlist_t * th_llist_foreach_cond(qlist_t *list, int (*func)(qlist_t *node), int *ret); + qlist_t * th_llist_find(qlist_t *list, const void *data); qlist_t * th_llist_find_func(qlist_t *list, const void *userdata, int (compare)(const void *, const void *));