

If you don\textquotesingle{}t know how to create lists see \mbox{\hyperlink{eina_list_01_example_page}{Adding elements to Eina\+\_\+\+List}}.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}\ **argv)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ (void)argc;}
\DoxyCodeLine{\ \ \ (void)argv;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__List}{Eina\_List}}\ *list\ =\ NULL,\ *other\_list\ =\ NULL;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__List}{Eina\_List}}\ *l;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{void}\ *data;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ cmp\_result;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Types__Group_ga1b31ffcc0d46eed63a2381c5a011b486}{Eina\_Compare\_Cb}}\ cmp\_func\ =\ (\mbox{\hyperlink{group__Eina__Types__Group_ga1b31ffcc0d46eed63a2381c5a011b486}{Eina\_Compare\_Cb}})strcmp;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(list,\ \textcolor{stringliteral}{"{}starbuck"{}});}
\DoxyCodeLine{\ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(list,\ \textcolor{stringliteral}{"{}appolo"{}});}
\DoxyCodeLine{\ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(list,\ \textcolor{stringliteral}{"{}boomer"{}});}

\end{DoxyCodeInclude}
This is the code we have already seen to create a list. Now if we need to search the list we can do it like this\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ data\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga5e876264e6b2de0485c4a701f447db80}{eina\_list\_search\_unsorted}}(list,\ cmp\_func,\ \textcolor{stringliteral}{"{}boomer"{}});}
\DoxyCodeLine{\ \ \ l\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga69fb43a00f39f78484893854a64cf4f9}{eina\_list\_search\_unsorted\_list}}(list,\ cmp\_func,\ \textcolor{stringliteral}{"{}boomer"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (l-\/>\mbox{\hyperlink{struct__Eina__List_a043e22d601d3a0504f30255a43a25e7a}{data}}\ !=\ data)}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}

\end{DoxyCodeInclude}
 However if searching the list multiple times it probably is better to sort the list since the sorted\+\_\+search functions are much faster\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga568115ea8231ca6baed243032570e15c}{eina\_list\_sort}}(list,\ 0,\ cmp\_func);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ data\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga18d9422a3f251d7d7205fb5e9708272d}{eina\_list\_search\_sorted}}(list,\ cmp\_func,\ \textcolor{stringliteral}{"{}starbuck"{}});}
\DoxyCodeLine{\ \ \ l\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga930d212790522a34f021dd67f03b141c}{eina\_list\_search\_sorted\_list}}(list,\ cmp\_func,\ \textcolor{stringliteral}{"{}starbuck"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (l-\/>\mbox{\hyperlink{struct__Eina__List_a043e22d601d3a0504f30255a43a25e7a}{data}}\ !=\ data)}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}

\end{DoxyCodeInclude}
 Once the list is sorted it\textquotesingle{}s not a good idea to use append/prepend functions since that would add the element in the wrong place, instead elements should be added with \mbox{\hyperlink{group__Eina__List__Group_gaa47bc3ae29d8fd946105560b94fc242c}{eina\+\_\+list\+\_\+sorted\+\_\+insert()}}\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_gaa47bc3ae29d8fd946105560b94fc242c}{eina\_list\_sorted\_insert}}(list,\ cmp\_func,\ \textcolor{stringliteral}{"{}helo"{}});}

\end{DoxyCodeInclude}
 A noteworthy use case is adding an element to a list only if it doesn\textquotesingle{}t exist already, this can accomplished by searching for the element that is closest to what is being added, and if that doesn\textquotesingle{}t match add\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ l\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga4e667216422b60be1d6636f821eddea2}{eina\_list\_search\_sorted\_near\_list}}(list,\ cmp\_func,\ \textcolor{stringliteral}{"{}hera"{}},\ \&cmp\_result);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (cmp\_result\ >\ 0)}
\DoxyCodeLine{\ \ \ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_gac2ae5d9426f552b9f70eb573582b491c}{eina\_list\_prepend\_relative\_list}}(list,\ \textcolor{stringliteral}{"{}hera"{}},\ l);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (cmp\_result\ <\ 0)}
\DoxyCodeLine{\ \ \ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_gaaf5cc0fb74a42e16757e5523bacdee53}{eina\_list\_append\_relative\_list}}(list,\ \textcolor{stringliteral}{"{}hera"{}},\ l);}

\end{DoxyCodeInclude}
\begin{DoxyNote}{Note}
\mbox{\hyperlink{group__Eina__List__Group_ga4e667216422b60be1d6636f821eddea2}{eina\+\_\+list\+\_\+search\+\_\+sorted\+\_\+near\+\_\+list()}} will tell you not only the nearest node to what was searched for but how it compares to your term, this way it is easy to know if you have to add before or after that node.
\end{DoxyNote}
It is sometimes useful to get a portion of the list as another list, here we take every element that comes after \char`\"{}boomer\char`\"{} and split it into \char`\"{}other\+\_\+list\char`\"{}\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ l\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga930d212790522a34f021dd67f03b141c}{eina\_list\_search\_sorted\_list}}(list,\ cmp\_func,\ \textcolor{stringliteral}{"{}boomer"{}});}
\DoxyCodeLine{\ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_gaf480f45d017b959f805927666ef6b2ff}{eina\_list\_split\_list}}(list,\ l,\ \&other\_list);}

\end{DoxyCodeInclude}
 It is also possible to add entire lists of elements using \mbox{\hyperlink{group__Eina__List__Group_ga13adb1de3565ccce834407b43d173bd8}{eina\+\_\+list\+\_\+sorted\+\_\+merge()}}\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ other\_list\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga568115ea8231ca6baed243032570e15c}{eina\_list\_sort}}(other\_list,\ 0,\ cmp\_func);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga13adb1de3565ccce834407b43d173bd8}{eina\_list\_sorted\_merge}}(list,\ other\_list,\ cmp\_func);}

\end{DoxyCodeInclude}
 And as always release memory and shutdown eina before ending\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__List__Group_ga82a1bfa543e21853f9ea3ff88dd1250b}{eina\_list\_free}}(list);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 The full source code can be found on the examples folder on the \mbox{\hyperlink{eina_list_02_c}{eina\+\_\+list\+\_\+02.c}} file. 