comparison 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
comparison
equal deleted inserted replaced
135:26fe4dab7e78 136:4ec36204d34e
1 /* 1 /*
2 * Generic utility-functions, macros and defaults 2 * Generic utility-functions, macros and defaults
3 * Programmed and designed by Matti 'ccr' Hamalainen 3 * Programmed and designed by Matti 'ccr' Hamalainen
4 * (C) Copyright 2002-2009 Tecnic Software productions (TNSP) 4 * (C) Copyright 2002-2010 Tecnic Software productions (TNSP)
5 * 5 *
6 * Please read file 'COPYING' for information on license and distribution. 6 * Please read file 'COPYING' for information on license and distribution.
7 */ 7 */
8 #ifndef _TH_UTIL_H 8 #ifndef _TH_UTIL_H
9 #define _TH_UTIL_H 9 #define _TH_UTIL_H
81 #define th_memset memset 81 #define th_memset memset
82 #else 82 #else
83 void *th_memset(void *, int, size_t); 83 void *th_memset(void *, int, size_t);
84 #endif 84 #endif
85 85
86
87 /* Doubly linked list handling
88 */
89 typedef struct _qlist_t {
90 void *data;
91 size_t num;
92 struct _qlist_t *prev, *next;
93 } qlist_t;
94
95
96 qlist_t * th_llist_new(void *data);
97 void th_llist_free(qlist_t *list);
98 void th_llist_free_func(qlist_t *list, void (*freefunc)(void *data));
99
100 qlist_t * th_llist_append(qlist_t **list, void *data);
101 qlist_t * th_llist_prepend(qlist_t **list, void *data);
102 void th_llist_delete(qlist_t **list, const void *data);
103 void th_llist_delete_node(qlist_t **list, qlist_t *node);
104
105 qlist_t * th_llist_get_nth(qlist_t *list, const size_t n);
106 size_t th_llist_length(const qlist_t *list);
107 ssize_t th_llist_position(const qlist_t *list, const qlist_t *node);
108
109 qlist_t * th_llist_find(qlist_t *list, const void *data);
110 qlist_t * th_llist_find_func(qlist_t *list, const void *userdata, int (compare)(const void *, const void *));
111
112
86 #ifdef __cplusplus 113 #ifdef __cplusplus
87 } 114 }
88 #endif 115 #endif
89 #endif /* _TH_UTIL_H */ 116 #endif /* _TH_UTIL_H */