00001 #ifndef DLLIST_H 00002 #define DLLIST_H 00003 00004 struct dl_node 00005 { 00006 struct dl_node *next; 00007 struct dl_node *prev; 00008 }; 00009 00010 struct dl_head 00011 { 00012 struct dl_node *first; 00013 struct dl_node *null; 00014 struct dl_node *last; 00015 }; 00016 00017 static inline struct dl_head * 00018 dl_init(struct dl_head *h) 00019 { 00020 h->first = (struct dl_node *)&h->null; 00021 h->null = 0; 00022 h->last = (struct dl_node *)&h->first; 00023 return h; 00024 } 00025 00026 static inline struct dl_node * 00027 dl_remove(struct dl_node *n) 00028 { 00029 n->prev->next = n->next; 00030 n->next->prev = n->prev; 00031 return n; 00032 } 00033 00034 static inline struct dl_node * 00035 dl_insert_after(struct dl_node *p, struct dl_node *n) 00036 { 00037 n->next = p->next; 00038 n->prev = p; 00039 p->next = n; 00040 n->next->prev = n; 00041 return n; 00042 } 00043 00044 #define dl_empty(h) ((h)->first->next == 0) 00045 #define dl_insert_before(p, n) dl_insert_after((p)->prev, (n)) 00046 #define dl_insert_first(h, n) ({ struct dl_node *_n = (n); \ 00047 dl_insert_before((h)->first, _n); }) 00048 #define dl_insert_last(h, n) ({ struct dl_node *_n = (n); \ 00049 dl_insert_after((h)->last, _n); }) 00050 #define dl_remove_first(h) dl_remove((h)->first) // mustn't be empty! 00051 #define dl_remove_last(h) dl_remove((h)->last) // mustn't be empty! 00052 00053 #endif /* DLLIST_H */ 00054
1.5.5