List
[Containers]
These functions provide list management.
More...
Data Structures | |
struct | _Eina_List |
A linked list node. More... | |
struct | _Eina_List_Accounting |
Defines | |
#define | EINA_LIST_FOREACH(list, l, data) for (l = list, data = eina_list_data_get(l); l; l = eina_list_next(l), data = eina_list_data_get(l)) |
Macro to iterate over a list easily. | |
#define | EINA_LIST_REVERSE_FOREACH(list, l, data) for (l = eina_list_last(list), data = eina_list_data_get(l); l; l = eina_list_prev(l), data = eina_list_data_get(l)) |
Macro to iterate over a list easily in the reverse order. | |
#define | EINA_LIST_FOREACH_SAFE(list, l, l_next, data) for (l = list, l_next = eina_list_next(l), data = eina_list_data_get(l); l; l = l_next, l_next = eina_list_next(l), data = eina_list_data_get(l)) |
Macro to iterate over a list easily, supporting deletion. | |
#define | EINA_LIST_REVERSE_FOREACH_SAFE(list, l, l_prev, data) for (l = list, l_prev = eina_list_prev(l), data = eina_list_data_get(l); l; l = l_prev, l_prev = eina_list_prev(l), data = eina_list_data_get(l)) |
Macro to iterate over a list easily in the reverse order, supporting deletion. | |
#define | EINA_LIST_FREE(list, data) for (data = list ? eina_list_data_get(list) : NULL; list; list = eina_list_remove_list(list, list), data = list ? eina_list_data_get(list) : NULL) |
Easy way to free the while list while being able to release its pointed data. | |
Typedefs | |
typedef struct _Eina_List | Eina_List |
Type for a generic single linked list. | |
typedef struct _Eina_List_Accounting | Eina_List_Accounting |
Functions | |
static Eina_List * | eina_list_last (const Eina_List *list) |
Get the last list node in the list. | |
static Eina_List * | eina_list_next (const Eina_List *list) |
Get the next list node after the specified list node. | |
static Eina_List * | eina_list_prev (const Eina_List *list) |
Get the previous list node before the specified list node. | |
static void * | eina_list_data_get (const Eina_List *list) |
Get the list node data member. | |
static unsigned int | eina_list_count (const Eina_List *list) |
Get the count of the number of items in a list. | |
EAPI int | eina_list_init (void) |
Initialize the list module. | |
EAPI int | eina_list_shutdown (void) |
Shut down the list module. | |
EAPI Eina_List * | eina_list_append (Eina_List *list, const void *data) |
Append the given data to the given linked list. | |
EAPI Eina_List * | eina_list_prepend (Eina_List *list, const void *data) |
Prepends the given data to the given linked list. | |
EAPI Eina_List * | eina_list_append_relative (Eina_List *list, const void *data, const void *relative) |
Insert the given data into the given linked list after the specified data. | |
EAPI Eina_List * | eina_list_append_relative_list (Eina_List *list, const void *data, Eina_List *relative) |
Append a list node to a linked list after the specified member. | |
EAPI Eina_List * | eina_list_prepend_relative (Eina_List *list, const void *data, const void *relative) |
Prepend a data pointer to a linked list before the specified member. | |
EAPI Eina_List * | eina_list_prepend_relative_list (Eina_List *list, const void *data, Eina_List *relative) |
Prepend a list node to a linked list before the specified member. | |
EAPI Eina_List * | eina_list_remove (Eina_List *list, const void *data) |
Remove the first instance of the specified data from the given list. | |
EAPI Eina_List * | eina_list_remove_list (Eina_List *list, Eina_List *remove_list) |
Remove the specified data. | |
EAPI Eina_List * | eina_list_promote_list (Eina_List *list, Eina_List *move_list) |
Move the specified data to the head of the list. | |
EAPI Eina_List * | eina_list_demote_list (Eina_List *list, Eina_List *move_list) |
Move the specified data to the tail of the list. | |
EAPI void * | eina_list_data_find (const Eina_List *list, const void *data) |
Find a member of a list and return the member. | |
EAPI Eina_List * | eina_list_data_find_list (const Eina_List *list, const void *data) |
Find a member of a list and return the list node containing that member. | |
EAPI Eina_List * | eina_list_free (Eina_List *list) |
Free an entire list and all the nodes, ignoring the data contained. | |
EAPI void * | eina_list_nth (const Eina_List *list, unsigned int n) |
Get the nth member's data pointer in a list. | |
EAPI Eina_List * | eina_list_nth_list (const Eina_List *list, unsigned int n) |
Get the nth member's list node in a list. | |
EAPI Eina_List * | eina_list_reverse (Eina_List *list) |
Reverse all the elements in the list. | |
EAPI Eina_List * | eina_list_reverse_clone (const Eina_List *list) |
Clone (copy) all the elements in the list in reverse order. | |
EAPI Eina_List * | eina_list_clone (const Eina_List *list) |
Clone (copy) all the elements in the list in exact order. | |
EAPI Eina_List * | eina_list_sort (Eina_List *list, unsigned int size, Eina_Compare_Cb func) |
Sort a list according to the ordering func will return. | |
EAPI Eina_List * | eina_list_merge (Eina_List *left, Eina_List *right) |
Merge two list. | |
EAPI Eina_List * | eina_list_sorted_merge (Eina_List *left, Eina_List *right, Eina_Compare_Cb func) |
Merge two sorted list according to the ordering func will return. | |
EAPI Eina_List * | eina_list_search_sorted_near_list (const Eina_List *list, Eina_Compare_Cb func, const void *data) |
EAPI Eina_List * | eina_list_search_sorted_list (const Eina_List *list, Eina_Compare_Cb func, const void *data) |
EAPI void * | eina_list_search_sorted (const Eina_List *list, Eina_Compare_Cb func, const void *data) |
EAPI Eina_List * | eina_list_search_unsorted_list (const Eina_List *list, Eina_Compare_Cb func, const void *data) |
EAPI void * | eina_list_search_unsorted (const Eina_List *list, Eina_Compare_Cb func, const void *data) |
EAPI Eina_Iterator * | eina_list_iterator_new (const Eina_List *list) |
Returned a new iterator asociated to a list. | |
EAPI Eina_Iterator * | eina_list_iterator_reversed_new (const Eina_List *list) |
Returned a new reversed iterator asociated to a list. | |
EAPI Eina_Accessor * | eina_list_accessor_new (const Eina_List *list) |
Returned a new accessor asociated to a list. |
Detailed Description
These functions provide list management.These functions provide single linked list management.
For more information, you can look at the List Tutorial.
Define Documentation
#define EINA_LIST_FOREACH | ( | list, | |||
l, | |||||
data | ) | for (l = list, data = eina_list_data_get(l); l; l = eina_list_next(l), data = eina_list_data_get(l)) |
Macro to iterate over a list easily.
- Parameters:
-
list The list to iterate over. l A list that is used as loop index. data The data.
list
in an easy way. It iterates from the first element to the last one. data
is the data of each element of the list. l
is an Eina_List that is used as counter.This macro can be used for freeing the data of alist, like in the following example:
Eina_List *list; Eina_List *l; char *data; // list is already filled, // its elements are just duplicated strings, // EINA_LIST_FOREACH will be used to free those strings EINA_LIST_FOREACH(list, l, data) free(data); eina_list_free(list);
- Note:
- this example is not optimal algorithm to release a list since it will walk the list twice, but it serves as an example. For optimized version use EINA_LIST_FREE()
- Warning:
- do not delete list nodes, specially the current node, while iterating. If you wish to do so, use EINA_LIST_FOREACH_SAFE().
Referenced by eina_list_append_relative(), eina_list_clone(), eina_list_data_find_list(), eina_list_prepend_relative(), and eina_list_reverse_clone().
#define EINA_LIST_REVERSE_FOREACH | ( | list, | |||
l, | |||||
data | ) | for (l = eina_list_last(list), data = eina_list_data_get(l); l; l = eina_list_prev(l), data = eina_list_data_get(l)) |
Macro to iterate over a list easily in the reverse order.
- Parameters:
-
list The list to iterate over. l A list that is used as loop index. data The data.
list
in an easy way. It iterates from the last element to the first one. data
is the data of each element of the list. l
is an Eina_List that is used as counter.This macro can be used for freeing the data of alist, like in the following example:
Eina_List *list; Eina_List *l; char *data; // list is already filled, // its elements are just duplicated strings, // EINA_LIST_REVERSE_FOREACH will be used to free those strings EINA_LIST_REVERSE_FOREACH(list, l, data) free(data); eina_list_free(list);
- Note:
- this example is not optimal algorithm to release a list since it will walk the list twice, but it serves as an example. For optimized version use EINA_LIST_FREE()
- Warning:
- do not delete list nodes, specially the current node, while iterating. If you wish to do so, use EINA_LIST_REVERSE_FOREACH_SAFE().
#define EINA_LIST_FOREACH_SAFE | ( | list, | |||
l, | |||||
l_next, | |||||
data | ) | for (l = list, l_next = eina_list_next(l), data = eina_list_data_get(l); l; l = l_next, l_next = eina_list_next(l), data = eina_list_data_get(l)) |
Macro to iterate over a list easily, supporting deletion.
- Parameters:
-
list The list to iterate over. l A list that is used as loop index. l_next A second list that is used as loop next index. data The data.
list
in an easy way. It iterates from the first element to the last one. data
is the data of each element of the list. l
is an Eina_List that is used as counter.
This is the safe version, which stores the next pointer in l_next
before proceeding, so deletion of current node is safe. If you wish to remove anything else, remember to set l_next
accordingly.
This macro can be used for freeing list nodes, like in the following example:
Eina_List *list; Eina_List *l; Eina_List *l_next; char *data; // list is already filled, // its elements are just duplicated strings, // EINA_LIST_FOREACH_SAFE will be used to free elements that match "key". EINA_LIST_FOREACH_SAFE(list, l, l_next, data) if (strcmp(data, "key") == 0) { free(data); list = eina_list_remove_list(list, l); }
#define EINA_LIST_REVERSE_FOREACH_SAFE | ( | list, | |||
l, | |||||
l_prev, | |||||
data | ) | for (l = list, l_prev = eina_list_prev(l), data = eina_list_data_get(l); l; l = l_prev, l_prev = eina_list_prev(l), data = eina_list_data_get(l)) |
Macro to iterate over a list easily in the reverse order, supporting deletion.
- Parameters:
-
list The list to iterate over. l A list that is used as loop index. l_prev A second list that is used as loop previous index. data The data.
list
in an easy way. It iterates from the last element to the first one. data
is the data of each element of the list. l
is an Eina_List that is used as counter.
This is the safe version, which stores the previous pointer in l_prev
before proceeding, so deletion of current node is safe. If you wish to remove anything else, remember to set l_prev
accordingly.
This macro can be used for freeing list nodes, like in the following example:
Eina_List *list; Eina_List *l; Eina_List *l_prev; char *data; // list is already filled, // its elements are just duplicated strings, // EINA_LIST_REVERSE_FOREACH_SAFE will be used to free elements that match "key". EINA_LIST_REVERSE_FOREACH_SAFE(list, l, l_prev, data) if (strcmp(data, "key") == 0) { free(data); list = eina_list_remove_list(list, l); }
#define EINA_LIST_FREE | ( | list, | |||
data | ) | for (data = list ? eina_list_data_get(list) : NULL; list; list = eina_list_remove_list(list, list), data = list ? eina_list_data_get(list) : NULL) |
Easy way to free the while list while being able to release its pointed data.
Eina_List *list; char *data; // list is already filled, // its elements are just duplicated strings, EINA_LIST_FREE(list, data) free(data);
If you do not need to release node data then use eina_list_free().
- See also:
- eina_list_free()
Function Documentation
Get the last list node in the list.
- Parameters:
-
list The list to get the last list node from.
- Returns:
- The last list node in the list.
list
is NULL
or empty, NULL
is returned.This is a order-1 operation (it takes the same short time regardless of the length of the list).
References _Eina_List::accounting.
Referenced by eina_list_iterator_reversed_new().
Get the next list node after the specified list node.
- Parameters:
-
list The list node to get the next list node from
- Returns:
- The next list node on success,
NULL
otherwise.
list
. It is equivalent to list->next. If list
is NULL
or if no next list node exists, it returns NULL
.
References _Eina_List::next.
Get the previous list node before the specified list node.
- Parameters:
-
list The list node to get the previous list node from.
- Returns:
- The previous list node o success,
NULL
otherwise. if no previous list node exists
list
. It is equivalent to list->prev. If list
is NULL
or if no previous list node exists, it returns NULL
.
References _Eina_List::prev.
static void * eina_list_data_get | ( | const Eina_List * | list | ) | [inline, static] |
Get the list node data member.
- Parameters:
-
list The list node to get the data member of.
- Returns:
- The data member from the list node.
list
. It is equivalent to list->data. If list
is NULL
, this function returns NULL
.
References _Eina_List::data.
static unsigned int eina_list_count | ( | const Eina_List * | list | ) | [inline, static] |
Get the count of the number of items in a list.
- Parameters:
-
list The list whose count to return.
- Returns:
- The number of members in the list.
list
contains. If the list is NULL
, 0 is returned.NB: This is an order-1 operation and takes the same tiem regardless of the length of the list.
References _Eina_List::accounting.
EAPI int eina_list_init | ( | void | ) |
Initialize the list module.
- Returns:
- 1 or greater on success, 0 on error.
References eina_error_init(), and EINA_ERROR_PERR.
EAPI int eina_list_shutdown | ( | void | ) |
Shut down the list module.
- Returns:
- 0 when the error module is completely shut down, 1 or greater otherwise.
References eina_error_shutdown().
Append the given data to the given linked list.
- Parameters:
-
list The given list. data The data to append.
- Returns:
- A list pointer.
data
to list
. If list
is NULL
, a new list is returned. On success, a new list pointer that should be used in place of the one given to this function is returned. Otherwise, the old pointer is returned.The following example code demonstrates how to ensure that the given data has been successfully appended.
Eina_List *list = NULL; extern void *my_data; list = eina_list_append(list, my_data); if (eina_error_get()) { fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n"); exit(-1); }
References _Eina_List::accounting, _Eina_List::data, eina_error_set(), _Eina_List::next, and _Eina_List::prev.
Referenced by eina_list_append_relative(), eina_list_append_relative_list(), and eina_list_clone().
Prepends the given data to the given linked list.
- Parameters:
-
list The given list. data The data to prepend.
- Returns:
- A list pointer.
data
to list
. If list
is NULL
, a new list is returned. On success, a new list pointer that should be used in place of the one given to this function is returned. Otherwise, the old pointer is returned.The following example code demonstrates how to ensure that the given data has been successfully prepended.
Example:
Eina_List *list = NULL; extern void *my_data; list = eina_list_prepend(list, my_data); if (eina_error_get()) { fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n"); exit(-1); }
References _Eina_List::data, eina_error_set(), _Eina_List::next, and _Eina_List::prev.
Referenced by eina_list_prepend_relative(), eina_list_prepend_relative_list(), and eina_list_reverse_clone().
EAPI Eina_List * eina_list_append_relative | ( | Eina_List * | list, | |
const void * | data, | |||
const void * | relative | |||
) |
Insert the given data into the given linked list after the specified data.
- Parameters:
-
list The given linked list. data The data to insert. relative The data to insert after.
- Returns:
- A list pointer.
data
to list
after relative
. If relative
is not in the list, data
is appended to the end of the list. If list
is NULL
, a new list is returned. If there are multiple instances of relative
in the list, data
is inserted after the first instance.On success, a new list pointer that should be used in place of the one given to this function is returned. Otherwise, the old pointer is returned.The following example code demonstrates how to ensure that the given data has been successfully inserted.
Eina_List *list = NULL; extern void *my_data; extern void *relative_member; list = eina_list_append(list, relative_member); if (eina_error_get()) { fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n"); exit(-1); } list = eina_list_append_relative(list, my_data, relative_member); if (eina_error_get()) { fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n"); exit(-1); }
References eina_list_append(), eina_list_append_relative_list(), and EINA_LIST_FOREACH.
EAPI Eina_List * eina_list_append_relative_list | ( | Eina_List * | list, | |
const void * | data, | |||
Eina_List * | relative | |||
) |
Append a list node to a linked list after the specified member.
- Parameters:
-
list The given linked list. data The data to insert. relative The list node to insert after.
- Returns:
- A list pointer.
data
to list
after the list node relative
. If list
or relative
are NULL
, data
is just appended to list
using eina_list_append(). If list
is NULL
, a new list is returned. If there are multiple instances of relative
in the list, data
is inserted after the first instance. On success, a new list pointer that should be used in place of the one given to this function is returned. Otherwise, the old pointer is returned.
References _Eina_List::accounting, _Eina_List::data, eina_error_set(), eina_list_append(), _Eina_List::next, and _Eina_List::prev.
Referenced by eina_list_append_relative().
EAPI Eina_List * eina_list_prepend_relative | ( | Eina_List * | list, | |
const void * | data, | |||
const void * | relative | |||
) |
Prepend a data pointer to a linked list before the specified member.
- Parameters:
-
list The given linked list. data The data to insert. relative The data to insert before.
- Returns:
- A list pointer.
data
to list
before relative
. If relative
is not in the list, data
is prepended to the list with eina_list_prepend(). If list
is NULL
, a new list is returned. If there are multiple instances of relative
in the list, data
is inserted before the first instance. On success, a new list pointer that should be used in place of the one given to this function is returned. Otherwise, the old pointer is returned.The following code example demonstrates how to ensure that the given data has been successfully inserted.
Eina_List *list = NULL; extern void *my_data; extern void *relative_member; list = eina_list_append(list, relative_member); if (eina_error_get_error()) { fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n"); exit(-1); } list = eina_list_prepend_relative(list, my_data, relative_member); if (eina_error_get()) { fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n"); exit(-1); }
References EINA_LIST_FOREACH, eina_list_prepend(), and eina_list_prepend_relative_list().
EAPI Eina_List * eina_list_prepend_relative_list | ( | Eina_List * | list, | |
const void * | data, | |||
Eina_List * | relative | |||
) |
Prepend a list node to a linked list before the specified member.
- Parameters:
-
list The given linked list. data The data to insert. relative The list node to insert before.
- Returns:
- A list pointer.
data
to list
before the list node relative
. If list
or relative
are NULL
, data
is just prepended to list
using eina_list_prepend(). If list
is NULL
, a new list is returned. If there are multiple instances of relative
in the list, data
is inserted before the first instance. On success, a new list pointer that should be used in place of the one given to this function is returned. Otherwise, the old pointer is returned.
References _Eina_List::data, eina_error_set(), eina_list_prepend(), _Eina_List::next, and _Eina_List::prev.
Referenced by eina_list_prepend_relative().
Remove the first instance of the specified data from the given list.
- Parameters:
-
list The given list. data The specified data.
- Returns:
- A list pointer.
data
from list
. If the specified data is not in the given list (tihis include the case where data
is NULL
), nothing is done. If list
is NULL
, NULL
is returned, otherwise a new list pointer that should be used in place of the one passed to this function.
References eina_list_data_find_list(), and eina_list_remove_list().
Remove the specified data.
- Parameters:
-
list The given linked list. remove_list The list node which is to be removed.
- Returns:
- A list pointer.
remove_list
from list
and frees the list node structure remove_list
. If list
is NULL
, this function returns NULL
. If remove_list
is NULL
, it returns list
, otherwise, a new list pointer that should be used in place of the one passed to this function.The following code gives an example.
extern Eina_List *list; Eina_List *l; extern void *my_data; void *data EINA_LIST_FOREACH(list, l, data) { if (data == my_data) { list = eina_list_remove_list(list, l); break; } }
References _Eina_List::accounting, _Eina_List::next, and _Eina_List::prev.
Referenced by eina_list_remove().
Move the specified data to the head of the list.
- Parameters:
-
list The list handle to move the data. move_list The list node to move.
- Returns:
- A new list handle to replace the old one
move_list
to the front of list
. If list is NULL
, NULL
is returned. If move_list
is NULL
, list
is returned. Otherwise, a new list pointer that should be used in place of the one passed to this function.Example:
extern Eina_List *list; Eina_List *l; extern void *my_data; void *data; EINA_LIST_FOREACH(list, l, data) { if (data == my_data) { list = eina_list_promote_list(list, l); break; } }
References _Eina_List::accounting, _Eina_List::next, and _Eina_List::prev.
Move the specified data to the tail of the list.
- Parameters:
-
list The list handle to move the data. move_list The list node to move.
- Returns:
- A new list handle to replace the old one
move_list
to the back of list
. If list is NULL
, NULL
is returned. If move_list
is NULL
, list
is returned. Otherwise, a new list pointer that should be used in place of the one passed to this function.Example:
extern Eina_List *list; Eina_List *l; extern void *my_data; void *data; EINA_LIST_FOREACH(list, l, data) { if (data == my_data) { list = eina_list_demote_list(list, l); break; } }
References _Eina_List::accounting, _Eina_List::next, and _Eina_List::prev.
EAPI void * eina_list_data_find | ( | const Eina_List * | list, | |
const void * | data | |||
) |
Find a member of a list and return the member.
- Parameters:
-
list The list to search for a data. data The data pointer to find in the list.
- Returns:
- The found member data pointer if foun,
NULL
otherwise.
list
from beginning to end for the first member whose data pointer is data
. If it is found, data
will be returned, otherwise NULL will be returned.Example:
extern Eina_List *list; extern void *my_data; if (eina_list_data_find(list, my_data) == my_data) { printf("Found member %p\n", my_data); }
References eina_list_data_find_list().
Find a member of a list and return the list node containing that member.
- Parameters:
-
list The list to search for data. data The data pointer to find in the list.
- Returns:
- The found members list node on success,
NULL
otherwise.
list
from beginning to end for the first member whose data pointer is data
. If it is found, the list node containing the specified member is returned, otherwise NULL
is returned.
References EINA_LIST_FOREACH.
Referenced by eina_list_data_find(), and eina_list_remove().
Free an entire list and all the nodes, ignoring the data contained.
- Parameters:
-
list The list to free
- Returns:
- A NULL pointer
list
. It does not free the data of the nodes. To free them, use EINA_LIST_FREE.
References _Eina_List::next.
EAPI void * eina_list_nth | ( | const Eina_List * | list, | |
unsigned int | n | |||
) |
Get the nth member's data pointer in a list.
- Parameters:
-
list The list to get the specified member number from. n The number of the element (0 being the first).
- Returns:
- The data pointer stored in the specified element.
n
, in the list
. The first element in the array is element number 0. If the element number n
does not exist, NULL
is returned. Otherwise, the data of the found element is returned.
References _Eina_List::data, and eina_list_nth_list().
Get the nth member's list node in a list.
- Parameters:
-
list The list to get the specfied member number from. n The number of the element (0 being the first).
- Returns:
- The list node stored in the numbered element.
n
, in @ list. The first element in the array is element number 0. If the element number n
does not exist or list
is NULL
or n
is greater than the count of elements in list
minus 1, NULL
is returned. Otherwise the list node stored in the numbered element is returned.
References _Eina_List::accounting, _Eina_List::next, and _Eina_List::prev.
Referenced by eina_list_nth(), and eina_list_sort().
Reverse all the elements in the list.
- Parameters:
-
list The list to reverse.
- Returns:
- The list head after it has been reversed.
list
, so the last member is now first, and so on. If list
is NULL
, this functon returns NULL
.
- Note:
- in-place: this will change the given list, so you should now point to the new list head that is returned by this function.
References _Eina_List::accounting, _Eina_List::data, _Eina_List::next, and _Eina_List::prev.
Clone (copy) all the elements in the list in reverse order.
- Parameters:
-
list The list to reverse.
- Returns:
- The new list that has been reversed.
list
, so the last member is now first, and so on. If list
is NULL
, this functon returns NULL
. This returns a copy of the given list.
- Note:
- copy: this will copy the list and you should then eina_list_free() when it is not required anymore.
- See also:
- eina_list_reverse()
References EINA_LIST_FOREACH, and eina_list_prepend().
Clone (copy) all the elements in the list in exact order.
- Parameters:
-
list The list to clone.
- Returns:
- The new list that has been cloned.
list
. If list
is NULL
, this functon returns NULL
. This returns a copy of the given list.
- Note:
- copy: this will copy the list and you should then eina_list_free() when it is not required anymore.
- See also:
- eina_list_reverse_clone()
References eina_list_append(), and EINA_LIST_FOREACH.
Sort a list according to the ordering func will return.
- Parameters:
-
list The list handle to sort. size The length of the list to sort. func A function pointer that can handle comparing the list data nodes.
- Returns:
- the new head of list.
list
. size
if the number of the first element to sort. If size
is 0 or greater than the number of elements in list
, all the elemnts are sorted. func
is used to compare two elements of list
. If list
or func
are NULL
, this function returns NULL
.
- Note:
- in-place: this will change the given list, so you should now point to the new list head that is returned by this function.
int sort_cb(const void *d1, const void *d2) { const char *txt = NULL; const char *txt2 = NULL; if(!d1) return(1); if(!d2) return(-1); return(strcmp((const char*)d1, (const char*)d2)); } extern Eina_List *list; list = eina_list_sort(list, eina_list_count(list), sort_cb);
References _Eina_List::accounting, _Eina_List::data, eina_list_nth_list(), _Eina_List::next, and _Eina_List::prev.
Merge two list.
- Parameters:
-
left Head list to merge. right Tail list to merge.
- Returns:
- A new merged list.
Both left and right does not exist anymore after the merge.
References _Eina_List::accounting, _Eina_List::next, and _Eina_List::prev.
EAPI Eina_List * eina_list_sorted_merge | ( | Eina_List * | left, | |
Eina_List * | right, | |||
Eina_Compare_Cb | func | |||
) |
Merge two sorted list according to the ordering func will return.
- Parameters:
-
left First list to merge. right Second list to merge. func A function pointer that can handle comparing the list data nodes.
- Returns:
- A new sorted list.
left
and right
, and choose the smallest one to be head of the returned list. It will continue this process for all entry of both list.
Both left and right does not exist anymore after the merge. If func
is NULL, it will return NULL.
Example:
int sort_cb(void *d1, void *d2) { const char *txt = NULL; const char *txt2 = NULL; if(!d1) return(1); if(!d2) return(-1); return(strcmp((const char*)d1, (const char*)d2)); } extern Eina_List *sorted1; extern Eina_List *sorted2; list = eina_list_sorted_merge(sorted1, sorted2, sort_cb);
References _Eina_List::accounting, _Eina_List::data, _Eina_List::next, and _Eina_List::prev.
EAPI Eina_Iterator * eina_list_iterator_new | ( | const Eina_List * | list | ) |
Returned a new iterator asociated to a list.
- Parameters:
-
list The list.
- Returns:
- A new iterator.
list
. If list
is NULL
or the count member of list
is less or equal than 0, this function still returns a valid iterator that will always return false on eina_iterator_next(), thus keeping API sane.If the memory can not be allocated, NULL is returned and EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is returned.
- Warning:
- if the list structure changes then the iterator becomes invalid! That is, if you add or remove nodes this iterator behavior is undefined and your program may crash!
References EINA_ERROR_OUT_OF_MEMORY, eina_error_set(), and _Eina_List::next.
EAPI Eina_Iterator * eina_list_iterator_reversed_new | ( | const Eina_List * | list | ) |
Returned a new reversed iterator asociated to a list.
- Parameters:
-
list The list.
- Returns:
- A new iterator.
list
. If list
is NULL
or the count member of list
is less or equal than 0, this function still returns a valid iterator that will always return false on eina_iterator_next(), thus keeping API sane.Unlike eina_list_iterator_new(), this will walk the list backwards.
If the memory can not be allocated, NULL is returned and EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is returned.
- Warning:
- if the list structure changes then the iterator becomes invalid! That is, if you add or remove nodes this iterator behavior is undefined and your program may crash!
References EINA_ERROR_OUT_OF_MEMORY, eina_error_set(), and eina_list_last().
EAPI Eina_Accessor * eina_list_accessor_new | ( | const Eina_List * | list | ) |
Returned a new accessor asociated to a list.
- Parameters:
-
list The list.
- Returns:
- A new accessor.
list
. If list
is NULL
or the count member of list
is less or equal than 0, this function returns NULL. If the memory can not be allocated, NULL is returned and EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid accessor is returned.
References EINA_ERROR_OUT_OF_MEMORY, and eina_error_set().