00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef _U_SIMPLE_LIST_H_
00038 #define _U_SIMPLE_LIST_H_
00039
00045 #define remove_from_list(elem) \
00046 do { \
00047 (elem)->next->prev = (elem)->prev; \
00048 (elem)->prev->next = (elem)->next; \
00049 } while (0)
00050
00057 #define insert_at_head(list, elem) \
00058 do { \
00059 (elem)->prev = list; \
00060 (elem)->next = (list)->next; \
00061 (list)->next->prev = elem; \
00062 (list)->next = elem; \
00063 } while(0)
00064
00071 #define insert_at_tail(list, elem) \
00072 do { \
00073 (elem)->next = list; \
00074 (elem)->prev = (list)->prev; \
00075 (list)->prev->next = elem; \
00076 (list)->prev = elem; \
00077 } while(0)
00078
00085 #define move_to_head(list, elem) \
00086 do { \
00087 remove_from_list(elem); \
00088 insert_at_head(list, elem); \
00089 } while (0)
00090
00097 #define move_to_tail(list, elem) \
00098 do { \
00099 remove_from_list(elem); \
00100 insert_at_tail(list, elem); \
00101 } while (0)
00102
00108 #define make_empty_list(sentinal) \
00109 do { \
00110 (sentinal)->next = sentinal; \
00111 (sentinal)->prev = sentinal; \
00112 } while (0)
00113
00121 #define first_elem(list) ((list)->next)
00122
00130 #define last_elem(list) ((list)->prev)
00131
00139 #define next_elem(elem) ((elem)->next)
00140
00148 #define prev_elem(elem) ((elem)->prev)
00149
00158 #define at_end(list, elem) ((elem) == (list))
00159
00167 #define is_empty_list(list) ((list)->next == (list))
00168
00178 #define foreach(ptr, list) \
00179 for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next )
00180
00194 #define foreach_s(ptr, t, list) \
00195 for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next)
00196
00197 #endif