wl_list

\class wl_list

\brief Doubly-linked list

On its own, an instance of struct wl_list represents the sentinel head of a doubly-linked list, and must be initialized using wl_list_init(). When empty, the list head's next and prev members point to the list head itself, otherwise next references the first element in the list, and prev refers to the last element in the list.

Use the struct wl_list type to represent both the list head and the links between elements within the list. Use wl_list_empty() to determine if the list is empty in O(1).

All elements in the list must be of the same type. The element type must have a struct wl_list member, often named link by convention. Prior to insertion, there is no need to initialize an element's link - invoking wl_list_init() on an individual list element's struct wl_list member is unnecessary if the very next operation is wl_list_insert(). However, a common idiom is to initialize an element's link prior to removal - ensure safety by invoking wl_list_init() before wl_list_remove().

Consider a list reference struct wl_list foo_list, an element type as struct element, and an element's link member as struct wl_list link.

The following code initializes a list and adds three elements to it.

\code struct wl_list foo_list;

struct element { int foo; struct wl_list link; }; struct element e1, e2, e3;

wl_list_init(&foo_list); wl_list_insert(&foo_list, &e1.link); // e1 is the first element wl_list_insert(&foo_list, &e2.link); // e2 is now the first element wl_list_insert(&e2.link, &e3.link); // insert e3 after e2 \endcode

The list now looks like <em>[e2, e3, e1]</em>.

The wl_list API provides some iterator macros. For example, to iterate a list in ascending order:

\code struct element *e; wl_list_for_each(e, foo_list, link) { do_something_with_element(e); } \endcode

See the documentation of each iterator for details. \sa http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/list.h

extern (C) nothrow
struct wl_list {}

Members

Variables

next
wl_list* next;

Next list element

prev
wl_list* prev;

Previous list element

Meta