Mercurial > hg > th-libs
changeset 757:2ab2fece83ea
Add th_llist_length_slow().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 01 Feb 2023 14:09:25 +0200 |
parents | 4bd82aca5e98 |
children | 72fb5ce9086a |
files | th_datastruct.c th_datastruct.h |
diffstat | 2 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/th_datastruct.c Wed Feb 01 14:09:12 2023 +0200 +++ b/th_datastruct.c Wed Feb 01 14:09:25 2023 +0200 @@ -203,6 +203,17 @@ } +size_t th_llist_length_slow(const th_llist_t *list) +{ + th_llist_t *curr = list; + size_t i; + + for (i = 0; curr != NULL; curr = curr->next, i++); + + return i; +} + + ssize_t th_llist_position(const th_llist_t *list, const th_llist_t *node) { const th_llist_t *curr = list;
--- a/th_datastruct.h Wed Feb 01 14:09:12 2023 +0200 +++ b/th_datastruct.h Wed Feb 01 14:09:25 2023 +0200 @@ -41,6 +41,7 @@ th_llist_t * th_llist_get_nth(th_llist_t *list, const size_t n); size_t th_llist_length(const th_llist_t *list); +size_t th_llist_length_slow(const th_llist_t *list); ssize_t th_llist_position(const th_llist_t *list, const th_llist_t *node); void th_llist_reverse(th_llist_t **list);