Lines Matching refs:list
36 * @file Classic doubly-link circular list implementation.
37 * For real usage examples of the linked list, see the file test/list.c
40 * We need to keep a list of struct foo in the parent struct bar, i.e. what
49 * We need one list head in bar and a list element in all list_of_foos (both are of
50 * data type 'struct list').
54 * struct list list_of_foos;
60 * struct list entry;
64 * Now we initialize the list head:
70 * Then we create the first element and add it to this list:
76 * Repeat the above for each element you want to add to the list. Deleting
82 * list again.
84 * Looping through the list requires a 'struct foo' as iterator and the
105 * The linkage struct for list nodes. This struct must be part of your
106 * to-be-linked struct. struct list is required for both the head of the
107 * list and for each list node.
109 * Position and name of the struct list field is irrelevant.
110 * There are no requirements that elements of a list are of the same type.
111 * There are no requirements for a list head, any struct list can be a list
114 struct list {
115 struct list *next, *prev;
119 * Initialize the list as an empty list.
124 * @param The list to initialized.
127 list_init(struct list *list)
129 list->next = list->prev = list;
133 __list_add(struct list *entry,
134 struct list *prev,
135 struct list *next)
144 * Insert a new element after the given list head. The new element does not
145 * need to be initialised as empty list.
146 * The list changes from:
155 * @param entry The new element to prepend to the list.
156 * @param head The existing list.
159 list_add(struct list *entry, struct list *head)
165 list_add_tail(struct list *entry, struct list *head)
170 static inline void list_replace(struct list *old,
171 struct list *new)
186 * Append a new element to the end of the list given with this list head.
188 * The list changes from:
197 * @param entry The new element to prepend to the list.
198 * @param head The existing list.
201 list_append(struct list *entry, struct list *head)
208 __list_del(struct list *prev, struct list *next)
216 _list_del(struct list *entry)
224 * Remove the element from the list it is in. Using this function will reset
225 * the pointers to/from this element so it is removed from the list. It does
228 * Using list_del on a pure list head (like in the example at the top of
230 * the list but rather reset the list as empty list.
238 list_del(struct list *entry)
244 static inline void list_move(struct list *list, struct list *head)
246 if (list->prev != head) {
247 _list_del(list);
248 list_add(list, head);
252 static inline void list_move_tail(struct list *list, struct list *head)
254 _list_del(list);
255 list_add_tail(list, head);
259 * Check if the list is empty.
264 * @return True if the list contains one or more elements or False otherwise.
267 list_is_empty(const struct list *head)
279 * Retrieve the first list entry for the given list pointer.
285 * @param ptr The list head
286 * @param type Data type of the list element to retrieve
287 * @param member Member name of the struct list field in the list element.
288 * @return A pointer to the first list element.
294 * Retrieve the last list entry for the given listpointer.
300 * @param ptr The list head
301 * @param type Data type of the list element to retrieve
302 * @param member Member name of the struct list field in the list element.
303 * @return A pointer to the last list element.
311 * Loop through the list given by head and set pos to struct in the list.
322 * @param pos Iterator variable of the type of the list elements.
324 * @param member Member name of the struct list in the list elements.
340 * Loop through the list, keeping a backup pointer to the element. This
341 * macro allows for the deletion of a list element while looping through the
342 * list.
355 #include <list.h>
358 list_add_tail(struct list *entry, struct list *head)
364 _list_del(struct list *entry)
371 static inline void list_replace(struct list *old,
372 struct list *new)
380 static inline void list_move(struct list *list, struct list *head)
382 if (list->prev != head) {
383 _list_del(list);
384 list_add(list, head);
388 static inline void list_move_tail(struct list *list, struct list *head)
390 _list_del(list);
391 list_add_tail(list, head);
413 static inline void __list_splice(const struct list *list,
414 struct list *prev,
415 struct list *next)
417 struct list *first = list->next;
418 struct list *last = list->prev;
427 static inline void list_splice(const struct list *list,
428 struct list *head)
430 if (!list_is_empty(list))
431 __list_splice(list, head, head->next);
434 static inline void list_splice_tail(const struct list *list,
435 struct list *head)
437 if (!list_is_empty(list))
438 __list_splice(list, head->prev, head);
441 static inline int list_is_singular(const struct list *list)
443 return list->next == list->prev;