diff options
Diffstat (limited to 'libqueue/queue/dl.h')
| -rw-r--r-- | libqueue/queue/dl.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libqueue/queue/dl.h b/libqueue/queue/dl.h new file mode 100644 index 0000000..e53843f --- /dev/null +++ b/libqueue/queue/dl.h @@ -0,0 +1,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*/ |
