Mercurial > hg > nnchat
diff th_util.h @ 136:4ec36204d34e
Add doubly linked list handling functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Nov 2010 21:31:11 +0200 |
parents | 0313fabd8049 |
children | 900768340e65 |
line wrap: on
line diff
--- a/th_util.h Sat Oct 30 21:08:21 2010 +0300 +++ b/th_util.h Tue Nov 02 21:31:11 2010 +0200 @@ -1,7 +1,7 @@ /* * Generic utility-functions, macros and defaults * Programmed and designed by Matti 'ccr' Hamalainen - * (C) Copyright 2002-2009 Tecnic Software productions (TNSP) + * (C) Copyright 2002-2010 Tecnic Software productions (TNSP) * * Please read file 'COPYING' for information on license and distribution. */ @@ -83,6 +83,33 @@ void *th_memset(void *, int, size_t); #endif + +/* Doubly linked list handling + */ +typedef struct _qlist_t { + void *data; + size_t num; + struct _qlist_t *prev, *next; +} qlist_t; + + +qlist_t * th_llist_new(void *data); +void th_llist_free(qlist_t *list); +void th_llist_free_func(qlist_t *list, void (*freefunc)(void *data)); + +qlist_t * th_llist_append(qlist_t **list, void *data); +qlist_t * th_llist_prepend(qlist_t **list, void *data); +void th_llist_delete(qlist_t **list, const void *data); +void th_llist_delete_node(qlist_t **list, qlist_t *node); + +qlist_t * th_llist_get_nth(qlist_t *list, const size_t n); +size_t th_llist_length(const qlist_t *list); +ssize_t th_llist_position(const qlist_t *list, const qlist_t *node); + +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 *)); + + #ifdef __cplusplus } #endif