logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

wl_list - Doubly-linked list.

Author

       Generated automatically by Doxygen for Wayland from the source code.

Version 1.24.0                              Mon Jul 28 2025 16:07:33                                  wl_list(3)

Detailed Description

       Doubly-linked list.

       On its own, an instance of struct wl_listrepresentsthesentinelheadofadoubly-linkedlist,andmustbeinitializedusingwl_list_init().Whenempty,thelisthead'snextandprevmemberspointtothelistheaditself,otherwisenextreferencesthefirstelementinthelist,andprevreferstothelastelementinthelist.

       Use the struct wl_listtypetorepresentboththelistheadandthelinksbetweenelementswithinthelist.Usewl_list_empty()todetermineifthelistisemptyinO(1).

       All elements in the list must be of the same type. The element type must have a struct wl_listmember,oftennamedlinkbyconvention.Priortoinsertion,thereisnoneedtoinitializeanelement'slink-invokingwl_list_init()onanindividuallistelement'sstructwl_listmemberisunnecessaryiftheverynextoperationiswl_list_insert().However,acommonidiomistoinitializeanelement'slinkpriortoremoval-ensuresafetybyinvokingwl_list_init()beforewl_list_remove().

       Consider a list reference struct wl_list foo_list,anelementtypeasstructelement,andanelement'slinkmemberasstructwl_listlink.

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

       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

       The list now looks like [e2,e3,e1].

       The wl_listAPIprovidessomeiteratormacros.Forexample,toiteratealistinascendingorder:

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

       See the documentation of each iterator for details.

       Seealsohttp://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/list.h

Field Documentation

structwl_list*wl_list::next
       Next list element

   structwl_list*wl_list::prev
       Previous list element

Member Function Documentation

intwl_list_empty(conststructwl_list*list)
       Determines if the list is empty.

       Parameterslist List whose emptiness is to be determined

       Returns
           1 if empty, or 0 if not empty

   voidwl_list_init(structwl_list*list)
       Initializes the list.

       Parameterslist List to initialize

   voidwl_list_insert(structwl_list*list,structwl_list*elm)
       Inserts an element into the list, after the element represented by list. When list is a reference to the
       list itself (the head), set the containing struct of elm as the first element in the list.

       Note
           If elm is already part of a list, inserting it again will lead to list corruption.

       Parameterslist List element after which the new element is inserted
           elm Link of the containing struct to insert into the list

   voidwl_list_insert_list(structwl_list*list,structwl_list*other)
       Inserts all of the elements of one list into another, after the element represented by list.

       Note
           This leaves other in an invalid state.

       Parameterslist List element after which the other list elements will be inserted
           other List of elements to insert

   intwl_list_length(conststructwl_list*list)
       Determines the length of the list.

       Note
           This is an O(n) operation.

       Parameterslist List whose length is to be determined

       Returns
           Number of elements in the list

   voidwl_list_remove(structwl_list*elm)
       Removes an element from the list.

       Note
           This operation leaves elm in an invalid state.

       Parameterselm Link of the containing struct to remove from the list

Name

       wl_list - Doubly-linked list.

Synopsis

       #include <wayland-util.h>

   PublicMemberFunctions
       void wl_list_init (struct wl_list *list)
       void wl_list_insert (struct wl_list *list, struct wl_list *elm)
       void wl_list_remove (struct wl_list *elm)
       int wl_list_length (const struct wl_list *list)
       int wl_list_empty (const struct wl_list *list)
       void wl_list_insert_list (struct wl_list *list, struct wl_list *other)

   DataFields
       struct wl_list * prev
       struct wl_list * nextRelatedSymbols
       (Note that these are not member symbols.)
       #define wl_list_for_each(pos,  head,  member)
       #define wl_list_for_each_safe(pos,  tmp,  head,  member)
       #define wl_list_for_each_reverse(pos,  head,  member)
       #define wl_list_for_each_reverse_safe(pos,  tmp,  head,  member)

See Also