-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlist.h
50 lines (40 loc) · 1.26 KB
/
dlist.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
#ifndef DLIST_H
#define DLIST_H
#ifdef __cplusplus
extern "C"{
#endif
/* double linked list */
typedef struct DLElement
{
struct DLElement *prev;
struct DLElement *next;
void *data;
} DLElement;
typedef struct DList
{
DLElement *head;
DLElement *tail;
int size;
void (*destroy)(void *data);
} DList;
extern void FreeDList(DList *lst);
extern DList* NewDList(void (*destroy)(void *data));
extern void dlist_init(DList *list, void (*destroy)(void *data));
extern void dlist_destroy(DList *list);
extern int dlist_ins_next(DList *list, DLElement *element, const void *data);
extern int dlist_ins_prev(DList *list, DLElement *element, const void *data);
extern int dlist_remove(DList *list, DLElement *element, void **data);
extern void dlist_empty(DList *list);
#define dlist_size(list) ((list)->size)
#define dlist_head(list) ((list)->head)
#define dlist_tail(list) ((list)->tail)
#define dlist_is_head(element) ((element)->prev == NULL ? 1 : 0)
#define dlist_is_tail(element) ((element)->next == NULL ? 1 : 0)
#define dlist_data(element) ((element)->data)
#define dlist_next(element) ((element)->next)
#define dlist_prev(element) ((element)->prev)
#define dlist_ins(list, data) (dlist_ins_next((list), dlist_tail((list)), data))
#ifdef __cplusplus
};
#endif
#endif