Lines Matching refs:list

7 #include <util/list.h>
12 #define GET_ITEM(list, item) ({ BytePointer<void> pointer((uint8*)item \
13 - list->offset); &pointer; })
14 #define GET_LINK(list, item) ({ BytePointer<list_link> pointer((uint8*)item \
15 + list->offset); &pointer; })
20 /** Initializes the list with a specified offset to the link
21 * structure in the items that will be part of the list.
25 list_init_etc(struct list *list, int32 offset)
27 list->link.next = list->link.prev = &list->link;
28 list->offset = offset;
33 list_init(struct list *list)
35 list_init_etc(list, 0);
39 /** Adds a link to the head of the list
43 list_add_link_to_head(struct list *list, void *_link)
47 link->next = list->link.next;
48 link->prev = &list->link;
50 list->link.next->prev = link;
51 list->link.next = link;
59 /** Adds a link to the tail of the list
63 list_add_link_to_tail(struct list *list, void *_link)
67 link->next = &list->link;
68 link->prev = list->link.prev;
70 list->link.prev->next = link;
71 list->link.prev = link;
79 /** Removes a link from the list it's currently in.
80 * Note: the link has to be in a list when you call this function.
98 get_next_link(struct list *list, list_link *link)
100 if (link->next == &list->link)
108 get_prev_link(struct list *list, list_link *link)
110 if (link->prev == &list->link)
118 * item is NULL, it returns the first entry in the list,
120 * Returns NULL if there aren't any more items in this list.
124 list_get_next_item(struct list *list, void *item)
129 return list_is_empty(list) ? NULL : GET_ITEM(list, list->link.next);
131 link = get_next_link(list, GET_LINK(list, item));
132 return link != NULL ? GET_ITEM(list, link) : NULL;
137 * item is NULL, it returns the last entry in the list,
139 * Returns NULL if there aren't any previous items in this list.
143 list_get_prev_item(struct list *list, void *item)
148 return list_is_empty(list) ? NULL : GET_ITEM(list, list->link.prev);
150 link = get_prev_link(list, GET_LINK(list, item));
151 return link != NULL ? GET_ITEM(list, link) : NULL;
156 list_get_last_item(struct list *list)
158 return list_is_empty(list) ? NULL : GET_ITEM(list, list->link.prev);
162 /** Adds an item to the end of the list.
167 list_add_item(struct list *list, void *item)
169 list_add_link_to_tail(list, GET_LINK(list, item));
173 /** Removes an item from the list.
178 list_remove_item(struct list *list, void *item)
180 list_remove_link(GET_LINK(list, item));
184 /** Inserts an item before another item in the list.
186 * the list.
190 list_insert_item_before(struct list *list, void *before, void *item)
196 list_add_item(list, item);
200 beforeLink = GET_LINK(list, before);
201 link = GET_LINK(list, item);
211 /** Removes the first item in the list and returns it.
212 * Returns NULL if the list is empty.
216 list_remove_head_item(struct list *list)
220 if (list_is_empty(list))
223 list_remove_link(link = list->link.next);
224 return GET_ITEM(list, link);
228 /** Removes the last item in the list and returns it.
229 * Returns NULL if the list is empty.
233 list_remove_tail_item(struct list *list)
237 if (list_is_empty(list))
240 list_remove_link(link = list->link.prev);
241 return GET_ITEM(list, link);
245 /** Moves the contents of the source list to the target list.
246 * The target list will be emptied before the items are moved;
251 list_move_to_list(struct list *sourceList, struct list *targetList)
260 // correct link pointers to this list
264 // empty source list