-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlist.h
51 lines (35 loc) · 875 Bytes
/
list.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
/* list.h -- linked lists */
/**
* \file list.h
*
* A linked list.
*/
#ifndef DATASTRUCT_LIST_H
#define DATASTRUCT_LIST_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdlib.h>
#define T list_t
typedef struct list
{
struct list *next;
}
T;
void list_init(T *anchor);
/* Anchor is assumed to be a static element whose only job is to point to
* the first element in the list. */
void list_add_to_head(T *anchor, T *item);
void list_remove(T *anchor, T *doomed);
typedef int (list_walk_callback_t)(T *, void *);
int list_walk(T *anchor, list_walk_callback_t *cb, void *opaque);
/* Searches the linked list looking for a key. The key is specified as an
* offset from the start of the linked list element. It is an int-sized unit.
*/
T *list_find(T *anchor, size_t keyloc, int key);
#undef T
#ifdef __cplusplus
}
#endif
#endif /* DATASTRUCT_LIST_H */