-
Notifications
You must be signed in to change notification settings - Fork 0
/
slist.h
66 lines (53 loc) · 1.3 KB
/
slist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* provides a single linked list
* Ralf Becker
* 2003
* $Id: slist.h,v 1.1.1.1 2004/06/04 11:31:44 becker Exp $
*/
#include <stdlib.h>
#ifndef _SLIST_H_
#define slist_foreach(_x,_data) \
for (_data = slist_first(_x); _data; _data = slist_next(_x))
typedef struct slist_elmt_ {
void *data;
struct slist_elmt_ *next;
} slist_elmt;
typedef struct slist_ {
slist_elmt *first;
slist_elmt *current;
slist_elmt *last;
int length;
void (*destroy)(void *);
} slist;
/* returns number of elements in list */
int slist_size (slist *_LIST);
/* returns pointer to first element of list
* or NULL
*/
void *slist_first(slist *_LIST);
/* advance the pointer on current element
* return -1 at the end of the list
*/
int slist_advance(slist *_LIST);
/* return pointer to the current element in list
* or NULL
*/
void *slist_current(slist *_LIST);
/* returns pointer to next element in list
* or NULL
*/
void *slist_next(slist *_LIST);
/* append to end of list
* error -1
*/
int slist_append (slist *_LIST, void *data);
/* initialize list
* returns Pointer of type slist
* error - NULL
*/
slist *slist_init(void (*destroy)(void *data));
/* remove elements from list */
void slist_clean(slist *_LIST);
/* remove complete list */
void slist_remove(slist **_LIST);
#define _SLIST_H_
#endif /* _SLIST_H_ */