summaryrefslogtreecommitdiff
path: root/libqueue/queue/dl.h
blob: e53843f77a3dd37610c65f2f55e80acb52a3ab21 (plain)
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
/* vim: set ts=4 sw=4 ai:
 * dl.h -- doubly linked list implementation derived from NetBSD's queue.h
 */

#ifndef DL_H
#define DL_H

struct dle {
	void *data;
	struct dle *next;
	struct dle **pprev;
};

struct dlh {
	struct dle *first;
};

#define dl_first(hd) ((hd)->first)
#define dl_next(e) ((e)->next)
#define dl_empty(hd) (((hd)->first) == NULL)
#define dl_init(hd) ((hd)->first = NULL)

#define dl_foreach(var,head) \
	for ((var) = ((head)->first); \
		(var) != NULL; \
		(var) = ((var)->next))

#define dl_foreach_safe(var,head,vnext) \
	for ((var) = ((head)->first); \
		(var) != NULL && ((vnext) = dl_next((var)), 1); \
		(var) = (vnext))

struct dlh *dl_new(void);
struct dle *dl_elem_new(void *);
void dl_insert_after(struct dle *, struct dle *);
void dl_insert_before(struct dle *, struct dle *);
void dl_insert_head(struct dlh *, struct dle *);
void dl_remove(struct dlh *, struct dle *);
void dl_replace(struct dle *, struct dle *);
void dl_move(struct dlh *, struct dlh *);
void dl_cleanup(struct dlh *, void (*)(void *));
struct dle *dl_find_from_data(struct dlh *, const void *, int (*)(const void *, const void *));

#endif/*!DL_H*/