Changeset df29f24 in mainline for uspace/lib/c/include/adt/list.h
- Timestamp:
- 2011-06-01T09:04:08Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0a7627b, c9f0975
- Parents:
- e51a514 (diff), 5d1b3aa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/list.h
re51a514 rdf29f24 49 49 * 50 50 */ 51 #define LIST_INITIALIZE(name) link_t name = { \ 52 .prev = &name, \ 53 .next = &name \ 54 } 51 #define LIST_INITIALIZE(name) \ 52 link_t name = { \ 53 .prev = &name, \ 54 .next = &name \ 55 } 56 57 #define list_get_instance(link, type, member) \ 58 ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member)))) 59 60 #define list_foreach(list, iterator) \ 61 for (link_t *iterator = (list).next; \ 62 iterator != &(list); iterator = iterator->next) 55 63 56 64 /** Initialize doubly-linked circular list link … … 71 79 * Initialize doubly-linked circular list. 72 80 * 73 * @param head Pointer to link_t structure representing head ofthe list.74 * 75 */ 76 static inline void list_initialize(link_t * head)77 { 78 head->prev = head;79 head->next = head;81 * @param list Pointer to link_t structure representing the list. 82 * 83 */ 84 static inline void list_initialize(link_t *list) 85 { 86 list->prev = list; 87 list->next = list; 80 88 } 81 89 … … 85 93 * 86 94 * @param link Pointer to link_t structure to be added. 87 * @param head Pointer to link_t structure representing head ofthe list.88 * 89 */ 90 static inline void list_prepend(link_t *link, link_t * head)91 { 92 link->next = head->next;93 link->prev = head;94 head->next->prev = link;95 head->next = link;95 * @param list Pointer to link_t structure representing the list. 96 * 97 */ 98 static inline void list_prepend(link_t *link, link_t *list) 99 { 100 link->next = list->next; 101 link->prev = list; 102 list->next->prev = link; 103 list->next = link; 96 104 } 97 105 … … 101 109 * 102 110 * @param link Pointer to link_t structure to be added. 103 * @param head Pointer to link_t structure representing head of the list. 104 * 105 */ 106 static inline void list_append(link_t *link, link_t *head) 107 { 108 link->prev = head->prev; 109 link->next = head; 110 head->prev->next = link; 111 head->prev = link; 112 } 113 114 /** Insert item before another item in doubly-linked circular list. */ 115 static inline void list_insert_before(link_t *l, link_t *r) 116 { 117 list_append(l, r); 118 } 119 120 /** Insert item after another item in doubly-linked circular list. */ 121 static inline void list_insert_after(link_t *r, link_t *l) 122 { 123 list_prepend(l, r); 111 * @param list Pointer to link_t structure representing the list. 112 * 113 */ 114 static inline void list_append(link_t *link, link_t *list) 115 { 116 link->prev = list->prev; 117 link->next = list; 118 list->prev->next = link; 119 list->prev = link; 120 } 121 122 /** Insert item before another item in doubly-linked circular list. 123 * 124 */ 125 static inline void list_insert_before(link_t *link, link_t *list) 126 { 127 list_append(link, list); 128 } 129 130 /** Insert item after another item in doubly-linked circular list. 131 * 132 */ 133 static inline void list_insert_after(link_t *link, link_t *list) 134 { 135 list_prepend(list, link); 124 136 } 125 137 … … 143 155 * Query emptiness of doubly-linked circular list. 144 156 * 145 * @param head Pointer to link_t structure representing head of the list. 146 * 147 */ 148 static inline int list_empty(link_t *head) 149 { 150 return ((head->next == head) ? 1 : 0); 157 * @param list Pointer to link_t structure representing the list. 158 * 159 */ 160 static inline int list_empty(link_t *list) 161 { 162 return (list->next == list); 163 } 164 165 /** Get head item of a list. 166 * 167 * @param list Pointer to link_t structure representing the list. 168 * 169 * @return Head item of the list. 170 * @return NULL if the list is empty. 171 * 172 */ 173 static inline link_t *list_head(link_t *list) 174 { 175 return ((list->next == list) ? NULL : list->next); 151 176 } 152 177 … … 205 230 } 206 231 207 #define list_get_instance(link, type, member) \ 208 ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member)))) 209 210 #define list_foreach(list, iterator) \ 211 for (link_t *iterator = (list).next; \ 212 iterator != &(list); iterator = iterator->next) 232 /** Get n-th item of a list. 233 * 234 * @param list Pointer to link_t structure representing the list. 235 * @param n Item number (indexed from zero). 236 * 237 * @return n-th item of the list. 238 * @return NULL if no n-th item found. 239 * 240 */ 241 static inline link_t *list_nth(link_t *list, unsigned int n) 242 { 243 unsigned int cnt = 0; 244 245 list_foreach(*list, link) { 246 if (cnt == n) 247 return link; 248 249 cnt++; 250 } 251 252 return NULL; 253 } 213 254 214 255 extern int list_member(const link_t *, const link_t *);
Note:
See TracChangeset
for help on using the changeset viewer.