- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files
- Examples

Data Structures | Macros | Typedefs | Functions
Inline List
Eina » Data Types » Containers

These functions provide inline list management. More...

## Data Structures
struct | _Eina_Inlist
| Inlined list type. More...

## Macros
#define | EINA_INLIST Eina_Inlist __in_list
| Used for declaring an inlist member in a struct.
#define | EINA_INLIST_GET(Inlist) (& ((Inlist)->__in_list))
| Utility macro to get the inlist object of a struct.
#define | EINA_INLIST_CONTAINER_GET(ptr,type)
| Utility macro to get the container object of an inlist. More...
#define | _EINA_INLIST_OFFSET(ref) ((char *)&(ref)->__in_list - (char *)(ref))
#define | _EINA_INLIST_CONTAINER(ref, ptr)
#define | EINA_INLIST_FOREACH(list, it)
#define | EINA_INLIST_FOREACH_SAFE(list, list2, it)
#define | EINA_INLIST_REVERSE_FOREACH(list, it)
#define | EINA_INLIST_REVERSE_FOREACH_FROM(list, it)
#define | EINA_INLIST_FREE(list, it) for (it = (__typeof__(it)) list; list; it = (__typeof__(it)) list)

## Typedefs
typedef struct _Eina_Inlist | Eina_Inlist
| Inlined list type.
typedef struct _Eina_Inlist_Sorted_State | Eina_Inlist_Sorted_State

## Functions
Eina_Inlist * | eina_inlist_append (Eina_Inlist *in_list, Eina_Inlist *in_item)
| Add a new node to end of a list. More...
Eina_Inlist * | eina_inlist_prepend (Eina_Inlist *in_list, Eina_Inlist *in_item)
| Add a new node to beginning of list. More...
Eina_Inlist * | eina_inlist_append_relative (Eina_Inlist *in_list, Eina_Inlist *in_item, Eina_Inlist *in_relative)
| Add a new node after the given relative item in list. More...
Eina_Inlist * | eina_inlist_prepend_relative (Eina_Inlist *in_list, Eina_Inlist *in_item, Eina_Inlist *in_relative)
| Add a new node before the given relative item in list. More...
Eina_Inlist * | eina_inlist_remove (Eina_Inlist *in_list, Eina_Inlist *in_item)
| Remove node from list. More...
Eina_Inlist * | eina_inlist_find (Eina_Inlist *in_list, Eina_Inlist *in_item)
| Find given node in list, returns itself if found, NULL if not. More...
Eina_Inlist * | eina_inlist_promote (Eina_Inlist *list, Eina_Inlist *item)
| Move existing node to beginning of list. More...
Eina_Inlist * | eina_inlist_demote (Eina_Inlist *list, Eina_Inlist *item)
| Move existing node to end of list. More...
static Eina_Inlist * | eina_inlist_first (const Eina_Inlist *list)
| Get the first list node in the list. More...
static Eina_Inlist * | eina_inlist_last (const Eina_Inlist *list)
| Get the last list node in the list. More...
unsigned int | eina_inlist_count (const Eina_Inlist *list)
| Get the count of the number of items in a list. More...
Eina_Iterator * | eina_inlist_iterator_new (const Eina_Inlist *in_list)
| Returns a new iterator associated to list. More...
Eina_Accessor * | eina_inlist_accessor_new (const Eina_Inlist *in_list)
| Returns a new accessor associated to a list. More...
Eina_Inlist * | eina_inlist_sorted_insert (Eina_Inlist *list, Eina_Inlist *item, Eina_Compare_Cb func)
| Insert a new node into a sorted list. More...
Eina_Inlist_Sorted_State * | eina_inlist_sorted_state_new (void)
| Create state with valid data in it. More...
int | eina_inlist_sorted_state_init (Eina_Inlist_Sorted_State *state, Eina_Inlist *list)
| Force an Eina_Inlist_Sorted_State to match the content of a list. More...
void | eina_inlist_sorted_state_free (Eina_Inlist_Sorted_State *state)
| Free an Eina_Inlist_Sorted_State. More...
Eina_Inlist * | eina_inlist_sorted_state_insert (Eina_Inlist *list, Eina_Inlist *item, Eina_Compare_Cb func, Eina_Inlist_Sorted_State *state)
| Insert a new node into a sorted list. More...
Eina_Inlist * | eina_inlist_sort (Eina_Inlist *head, Eina_Compare_Cb func)
| Sort a list according to the ordering func will return. More...

## Detailed Description

These functions provide inline list management.

Inline lists mean its nodes pointers are part of same memory as data. This has the benefit of fragmenting memory less and avoiding `node->data` indirection, but has the drawback of higher cost for some common operations like count and sort.

It is possible to have inlist nodes to be part of regular lists, created with eina_list_append() or eina_list_prepend(). It's also possible to have a structure with two inlist pointers, thus be part of two different inlists at the same time, but the current convenience macros provided won't work for both of them. Consult Advanced Usage for more info.

Inline lists have their purposes, but if you don't know what those purposes are, go with regular lists instead.

Tip: When using inlists in more than one place (that is, passing them around functions or keeping a pointer to them in a structure) it's more correct to keep a pointer to the first container, and not a pointer to the first inlist item (mostly they are the same, but that's not always correct). This lets the compiler to do type checking and let the programmer know exactly what type this list is.

A simple example demonstrating the basic usage of an inlist can be found here: Eina_Inlist basic usage

# Algorithm

The basic structure can be represented by the following picture:

One data structure will also have the node information, with three pointers: prev, next and last. The last pointer is just valid for the first element (the list head), otherwise each insertion in the list would have to be done updating every node with the correct pointer. This means that it's always very important to keep a pointer to the first element of the list, since it is the only one that has the correct information to allow a proper O(1) append to the list.

# Performance

Due to the nature of the inlist, there's no accounting information, and no easy access to the last element from each list node. This means that eina_inlist_count() is order-N, while eina_list_count() is order-1 (constant time).

# Advanced Usage

The basic usage considers a struct that will have the user data, and also have an inlist node information (prev, next and last pointers) created with EINA_INLIST during the struct declaration. This allows one to use the convenience macros EINA_INLIST_GET(), EINA_INLIST_CONTAINER_GET(), EINA_INLIST_FOREACH() and so. This happens because the EINA_INLIST macro declares a struct member with the name __inlist, and all the other macros assume that this struct member has this name.

It may be the case that someone needs to have some inlist nodes added to a Eina_List too. If this happens, the inlist nodes can be added to the Eina_List without any problems. This example demonstrates this case: Eina_Inlist advanced usage - lists and inlists

It's also possible to have some data that is part of two different inlists. If this is the case, then it won't be possible to use the convenience macros to both of the lists. It will be necessary to create a new set of macros that will allow access to the second list node info. An example for this usage can be found here: Eina_Inlist advanced usage - multi-inlists

List of examples:

- Eina_Inlist basic usage
- Eina_Inlist advanced usage - lists and inlists
- Eina_Inlist advanced usage - multi-inlists

## Macro Definition Documentation

#define EINA_INLIST_CONTAINER_GET | ( |  | ptr,
|  |  | type
| ) |  |

Value:
((type *)((char *)ptr - \
offsetof(type, __in_list)))

Utility macro to get the container object of an inlist.

Examples:
  eina_inlist_01.c, eina_inlist_02.c, and eina_inlist_03.c.

#define _EINA_INLIST_OFFSET | ( |  | ref | ) | ((char *)&(ref)->__in_list - (char *)(ref))

Parameters

  ref | The reference to be used.

#define _EINA_INLIST_CONTAINER | ( |  | ref,
|  |  | ptr
| ) |  |

Value:
(void *)((char *)(ptr) - \
_EINA_INLIST_OFFSET(ref))
_EINA_INLIST_OFFSET
#define _EINA_INLIST_OFFSET(ref)
Definition: eina_inlist.h:805

Parameters

  ref | The reference to be used.
  ptr | The pointer to be used.

Referenced by evas_textblock_cursor_geometry_bidi_get().

#define EINA_INLIST_FOREACH | ( |  | list,
|  |  | it
| ) |  |

Value:
for (it = NULL, it = (list ? _EINA_INLIST_CONTAINER(it, list) : NULL); it; \
it = (EINA_INLIST_GET(it)->next ? _EINA_INLIST_CONTAINER(it, EINA_INLIST_GET(it)->next) : NULL))
_EINA_INLIST_CONTAINER
#define _EINA_INLIST_CONTAINER(ref, ptr)
Definition: eina_inlist.h:813
EINA_INLIST_GET
#define EINA_INLIST_GET(Inlist)
Utility macro to get the inlist object of a struct.
Definition: eina_inlist.h:415

Parameters

  list | The list to iterate on.
  it | The pointer to the list item, i.e. a pointer to each item that is part of the list.

Examples:
  eina_inlist_01.c, eina_inlist_02.c, and eina_inlist_03.c.

Referenced by ecore_evas_ecore_evas_list_get(), ecore_timer_dump(), ecore_wl_window_free(), eina_benchmark_run(), eina_log_domain_level_get(), eina_log_domain_level_set(), eina_rectangle_pool_release(), eina_threads_shutdown(), eldbus_connection_event_callback_del(), eldbus_name_owner_changed_callback_del(), eldbus_object_event_callback_del(), eldbus_proxy_event_callback_del(), eldbus_service_object_manager_detach(), evas_event_callback_del(), evas_event_callback_del_full(), evas_object_event_callback_del(), evas_object_event_callback_del_full(), evas_object_smart_callback_del(), evas_object_smart_callback_del_full(), evas_textblock_cursor_char_coord_set(), evas_textblock_cursor_line_char_first(), evas_textblock_cursor_line_char_last(), and evas_textblock_cursor_line_coord_set().

#define EINA_INLIST_FOREACH_SAFE | ( |  | list,
|  |  | list2,
|  |  | it
| ) |  |

Value:
for (it = NULL, it = (list ? _EINA_INLIST_CONTAINER(it, list) : NULL), list2 = it ? EINA_INLIST_GET(it)->next : NULL; \
it; \
it = NULL, it = list2 ? _EINA_INLIST_CONTAINER(it, list2) : NULL, list2 = list2 ? list2->next : NULL)
_EINA_INLIST_CONTAINER
#define _EINA_INLIST_CONTAINER(ref, ptr)
Definition: eina_inlist.h:813
EINA_INLIST_GET
#define EINA_INLIST_GET(Inlist)
Utility macro to get the inlist object of a struct.
Definition: eina_inlist.h:415

Parameters

  list | The list to iterate on.
  list2 | Auxiliar Eina_Inlist variable so we can save the pointer to the next element, allowing us to free/remove the current one. Note that this macro is only safe if the next element is not removed. Only the current one is allowed to be removed.
  it | The pointer to the list item, i.e. a pointer to each item that is part of the list.

Referenced by ecore_wl_screen_size_get().

#define EINA_INLIST_REVERSE_FOREACH | ( |  | list,
|  |  | it
| ) |  |

Value:
for (it = NULL, it = (list ? _EINA_INLIST_CONTAINER(it, list->last) : NULL); \
it; it = (EINA_INLIST_GET(it)->prev ? _EINA_INLIST_CONTAINER(it, EINA_INLIST_GET(it)->prev) : NULL))
_EINA_INLIST_CONTAINER
#define _EINA_INLIST_CONTAINER(ref, ptr)
Definition: eina_inlist.h:813
EINA_INLIST_GET
#define EINA_INLIST_GET(Inlist)
Utility macro to get the inlist object of a struct.
Definition: eina_inlist.h:415

Parameters

  list | The list to traversed in reverse order.
  it | The pointer to the list item, i.e. a pointer to each item that is part of the list.

Referenced by eina_counter_dump().

#define EINA_INLIST_REVERSE_FOREACH_FROM | ( |  | list,
|  |  | it
| ) |  |

Value:
for (it = NULL, it = (list ? _EINA_INLIST_CONTAINER(it, list) : NULL); \
it; it = (EINA_INLIST_GET(it)->prev ? _EINA_INLIST_CONTAINER(it, EINA_INLIST_GET(it)->prev) : NULL))
_EINA_INLIST_CONTAINER
#define _EINA_INLIST_CONTAINER(ref, ptr)
Definition: eina_inlist.h:813
EINA_INLIST_GET
#define EINA_INLIST_GET(Inlist)
Utility macro to get the inlist object of a struct.
Definition: eina_inlist.h:415

Parameters

  list | The last list to traversed in reverse order.
  it | The pointer to the list item, i.e. a pointer to each item that is part of the list.

See also
  EINA_INLIST_REVERSE_FOREACH()

Since
  1.8

EINA_INLIST_REVERSE_FOREACH() starts from last list of the given list. This starts from given list, not the last one.

#define EINA_INLIST_FREE | ( |  | list,
|  |  | it
| ) |  | for (it = (__typeof__(it)) list; list; it = (__typeof__(it)) list)

Parameters

  list | The list to free.
  it | The pointer to the list item, i.e. a pointer to each item that is part of the list.

NOTE: it is the duty of the body loop to properly remove the item from the inlist and free it. This function will turn into a infinite loop if you don't remove all items from the list.

Since
  1.8

## Typedef Documentation

Eina_Inlist_Sorted_State

Since
  1.1.0 State of sorted Eina_Inlist

## Function Documentation

Eina_Inlist* eina_inlist_append | ( | Eina_Inlist * | in_list,
|  | Eina_Inlist * | in_item
| ) |  |

Add a new node to end of a list.

Note
  this code is meant to be fast: appends are O(1) and do not walk in_list.
  in_item is considered to be in no list. If it was in another list before, eina_inlist_remove() it before adding. No check of new_l prev and next pointers is done, so it's safe to have them uninitialized.

Parameters

  in_list | existing list head or `NULL` to create a new list.
  in_item | new list node, must not be `NULL`.

Returns
  the new list head. Use it and not in_list anymore.

References _Eina_Inlist::last, _Eina_Inlist::next, and _Eina_Inlist::prev.

Referenced by ecore_event_filter_add(), ecore_event_handler_add(), ecore_main_fd_handler_file_add(), ecore_wl_subsurf_create(), eina_benchmark_register(), eina_inlist_append_relative(), eina_inlist_sorted_insert(), eina_inlist_sorted_state_insert(), eina_log_domain_level_set(), eina_simple_xml_attribute_new(), eina_simple_xml_node_tag_new(), eldbus_connection_event_callback_add(), eldbus_message_iter_container_new(), eldbus_message_iter_get_and_next(), eldbus_name_owner_changed_callback_add(), eldbus_object_event_callback_add(), eldbus_object_send(), eldbus_proxy_event_callback_add(), evas_event_callback_priority_add(), evas_object_event_callback_priority_add(), evas_object_smart_callback_priority_add(), evas_textblock_cursor_format_append(), evas_textblock_cursor_text_append(), evas_textblock_style_set(), and efl::eina::inlist< T, Allocator >::push_back().

Eina_Inlist* eina_inlist_prepend | ( | Eina_Inlist * | in_list,
|  | Eina_Inlist * | in_item
| ) |  |

Add a new node to beginning of list.

Note
  this code is meant to be fast: appends are O(1) and do not walk in_list.
  new_l is considered to be in no list. If it was in another list before, eina_inlist_remove() it before adding. No check of new_l prev and next pointers is done, so it's safe to have them uninitialized.

Parameters

  in_list | existing list head or `NULL` to create a new list.
  in_item | new list node, must not be `NULL`.

Returns
  the new list head. Use it and not in_list anymore.

References _Eina_Inlist::last, _Eina_Inlist::next, and _Eina_Inlist::prev.

Referenced by eina_counter_start(), eina_inlist_prepend_relative(), eina_inlist_sorted_insert(), eina_inlist_sorted_state_insert(), eina_rectangle_pool_request(), evas_textblock_cursor_format_append(), and efl::eina::inlist< T, Allocator >::push_front().

Eina_Inlist* eina_inlist_append_relative | ( | Eina_Inlist * | in_list,
|  | Eina_Inlist * | in_item,
|  | Eina_Inlist * | in_relative
| ) |  |

Add a new node after the given relative item in list.

Note
  this code is meant to be fast: appends are O(1) and do not walk in_list.
  in_item_l is considered to be in no list. If it was in another list before, eina_inlist_remove() it before adding. No check of in_item prev and next pointers is done, so it's safe to have them uninitialized.
  in_relative is considered to be inside in_list, no checks are done to confirm that and giving nodes from different lists will lead to problems. Giving NULL in_relative is the same as eina_list_append().

Parameters

  in_list | existing list head or `NULL` to create a new list.
  in_item | new list node, must not be `NULL`.
  in_relative | reference node, in_item will be added after it.

Returns
  the new list head. Use it and not list anymore.

References eina_inlist_append(), _Eina_Inlist::last, _Eina_Inlist::next, and _Eina_Inlist::prev.

Referenced by eina_inlist_sorted_insert(), eina_inlist_sorted_state_insert(), and evas_textblock_cursor_format_append().

Eina_Inlist* eina_inlist_prepend_relative | ( | Eina_Inlist * | in_list,
|  | Eina_Inlist * | in_item,
|  | Eina_Inlist * | in_relative
| ) |  |

Add a new node before the given relative item in list.

Note
  this code is meant to be fast: appends are O(1) and do not walk in_list.
  in_item is considered to be in no list. If it was in another list before, eina_inlist_remove() it before adding. No check of in_item prev and next pointers is done, so it's safe to have them uninitialized.
  in_relative is considered to be inside in_list, no checks are done to confirm that and giving nodes from different lists will lead to problems. Giving NULL in_relative is the same as eina_list_prepend().

Parameters

  in_list | existing list head or `NULL` to create a new list.
  in_item | new list node, must not be `NULL`.
  in_relative | reference node, in_item will be added before it.

Returns
  the new list head. Use it and not in_list anymore.

References eina_inlist_prepend(), _Eina_Inlist::last, _Eina_Inlist::next, and _Eina_Inlist::prev.

Referenced by eina_inlist_sorted_insert(), eina_inlist_sorted_state_insert(), and evas_textblock_cursor_format_append().

Eina_Inlist* eina_inlist_remove | ( | Eina_Inlist * | in_list,
|  | Eina_Inlist * | in_item
| ) |  |

Remove node from list.

Note
  this code is meant to be fast: appends are O(1) and do not walk list.
  in_item is considered to be inside in_list, no checks are done to confirm that and giving nodes from different lists will lead to problems, especially if in_item is the head since it will be different from list and the wrong new head will be returned.

Parameters

  in_list | existing list head, must not be `NULL`.
  in_item | existing list node, must not be `NULL`.

Returns
  the new list head. Use it and not list anymore.

References EINA_LOG_ERR, EINA_UNLIKELY, _Eina_Inlist::last, _Eina_Inlist::next, and _Eina_Inlist::prev.

Referenced by ecore_poller_del(), eina_benchmark_free(), eina_counter_free(), eina_rectangle_pool_release(), eina_simple_xml_attribute_free(), eldbus_name_owner_changed_callback_del(), efl::eina::inlist< T, Allocator >::erase(), evas_event_callback_del(), evas_event_callback_del_full(), evas_object_event_callback_del(), evas_object_event_callback_del_full(), evas_object_smart_callback_del(), evas_object_smart_callback_del_full(), efl::eina::inlist< T, Allocator >::pop_back(), and efl::eina::inlist< T, Allocator >::pop_front().

Eina_Inlist* eina_inlist_find | ( | Eina_Inlist * | in_list,
|  | Eina_Inlist * | in_item
| ) |  |

Find given node in list, returns itself if found, NULL if not.

Warning
  this is an expensive call and has O(n) cost, possibly walking the whole list.

Parameters

  in_list | existing list to search in_item in, must not be `NULL`.
  in_item | what to search for, must not be `NULL`.

Returns
  in_item if found, `NULL` if not.

References _Eina_Inlist::next.

Eina_Inlist* eina_inlist_promote | ( | Eina_Inlist * | list,
|  | Eina_Inlist * | item
| ) |  |

Move existing node to beginning of list.

Note
  this code is meant to be fast: appends are O(1) and do not walk list.
  item is considered to be inside list. No checks are done to confirm this, and giving nodes from different lists will lead to problems.

Parameters

  list | existing list head or `NULL` to create a new list.
  item | list node to move to beginning (head), must not be `NULL`.

Returns
  the new list head. Use it and not list anymore.

References _Eina_Inlist::last, _Eina_Inlist::next, and _Eina_Inlist::prev.

Eina_Inlist* eina_inlist_demote | ( | Eina_Inlist * | list,
|  | Eina_Inlist * | item
| ) |  |

Move existing node to end of list.

Note
  this code is meant to be fast: appends are O(1) and do not walk list.
  item is considered to be inside list. No checks are done to confirm this, and giving nodes from different lists will lead to problems.

Parameters

  list | existing list head or `NULL` to create a new list.
  item | list node to move to end (tail), must not be `NULL`.

Returns
  the new list head. Use it and not list anymore.

References _Eina_Inlist::last, _Eina_Inlist::next, and _Eina_Inlist::prev.

static Eina_Inlist* eina_inlist_first | ( | const Eina_Inlist * | list | ) |
| inline static

Get the first list node in the list.

Parameters

  list | The list to get the first list node from.

Returns
  The first list node in the list.

This function returns the first list node in the list `list`. If `list` is `NULL`, `NULL` is returned.

This is a O(N) operation (it takes time proportional to the length of the list).

Since
  1.8

static Eina_Inlist* eina_inlist_last | ( | const Eina_Inlist * | list | ) |
| inline static

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.

This function returns the last list node in the list `list`. If `list` is `NULL`, `NULL` is returned.

This is a O(N) operation (it takes time proportional to the length of the list).

Since
  1.8

unsigned int eina_inlist_count | ( | const Eina_Inlist * | list | ) |

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.

This function returns how many members `list` contains. If the list is `NULL`, `0` is returned.

Warning
  This is an order-N operation and so the time will depend on the number of elements on the list, so, it might become slow for big lists!

References _Eina_Inlist::next.

Eina_Iterator* eina_inlist_iterator_new | ( | const Eina_Inlist * | in_list | ) |

Returns a new iterator associated to list.

Parameters

  in_list | The list.

Returns
  A new iterator.

This function returns a newly allocated iterator associated to `in_list`. If `in_list` is `NULL` or the count member of `in_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. Otherwise, a valid iterator is returned.

Warning
  if the list structure changes then the iterator becomes invalid, and if you add or remove nodes iterator behavior is undefined, and your program may crash!

References EINA_MAGIC_SET, FUNC_ITERATOR_FREE, FUNC_ITERATOR_GET_CONTAINER, and FUNC_ITERATOR_NEXT.

Eina_Accessor* eina_inlist_accessor_new | ( | const Eina_Inlist * | in_list | ) |

Returns a new accessor associated to a list.

Parameters

  in_list | The list.

Returns
  A new accessor.

This function returns a newly allocated accessor associated to `in_list`. If `in_list` is `NULL` or the count member of `in_list` is less or equal than `0`, this function returns `NULL`. If the memory can not be allocated, `NULL` is returned and Otherwise, a valid accessor is returned.

References EINA_MAGIC_SET, FUNC_ACCESSOR_FREE, FUNC_ACCESSOR_GET_AT, and FUNC_ACCESSOR_GET_CONTAINER.

Referenced by efl::eina::inlist< T, Allocator >::accessor().

Eina_Inlist* eina_inlist_sorted_insert | ( | Eina_Inlist * | list,
|  | Eina_Inlist * | item,
|  | Eina_Compare_Cb | func
| ) |  |

Insert a new node into a sorted list.

Parameters

  list | The given linked list, must be sorted.
  item | list node to insert, must not be `NULL`.
  func | The function called for the sort.

Returns
  A list pointer.

Since
  1.1.0

This function inserts item into a linked list assuming it was sorted and the result will be sorted. If `list` is `NULLL`, item 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.

Note
  O(log2(n)) comparisons (calls to `func`) average/worst case performance. As said in eina_list_search_sorted_near_list(), lists do not have O(1) access time, so walking to the correct node can be costly, consider worst case to be almost O(n) pointer dereference (list walk).

References eina_inlist_append(), eina_inlist_append_relative(), eina_inlist_prepend(), eina_inlist_prepend_relative(), eina_inlist_sorted_state_init(), and _Eina_Inlist::next.

Eina_Inlist_Sorted_State* eina_inlist_sorted_state_new | ( | void |  | ) |

Create state with valid data in it.

Returns
  A valid Eina_Inlist_Sorted_State.

Since
  1.1.0

See eina_inlist_sorted_state_insert() for more information.

int eina_inlist_sorted_state_init | ( | Eina_Inlist_Sorted_State * | state,
|  | Eina_Inlist * | list
| ) |  |

Force an Eina_Inlist_Sorted_State to match the content of a list.

Parameters

  state | The state to update
  list | The list to match

Returns
  The number of item in the actually in the list

Since
  1.1.0

See eina_inlist_sorted_state_insert() for more information. This function is usefull if you didn't use eina_inlist_sorted_state_insert() at some point, but still think you have a sorted list. It will only correctly work on a sorted list.

References _Eina_Inlist::next.

Referenced by eina_inlist_sorted_insert().

void eina_inlist_sorted_state_free | ( | Eina_Inlist_Sorted_State * | state | ) |

Free an Eina_Inlist_Sorted_State.

Parameters

  state | The state to destroy

Since
  1.1.0

See eina_inlist_sorted_state_insert() for more information.

Eina_Inlist* eina_inlist_sorted_state_insert | ( | Eina_Inlist * | list,
|  | Eina_Inlist * | item,
|  | Eina_Compare_Cb | func,
|  | Eina_Inlist_Sorted_State * | state
| ) |  |

Insert a new node into a sorted list.

Parameters

  list | The given linked list, must be sorted.
  item | list node to insert, must not be `NULL`.
  func | The function called for the sort.
  state | The current array for initial dichotomic search

Returns
  A list pointer.

Since
  1.1.0

This function inserts item into a linked list assuming `state` match the exact content order of the list. It use `state` to do a fast first step dichotomic search before starting to walk the inlist itself. This make this code much faster than eina_inlist_sorted_insert() as it doesn't need to walk the list at all. The result is of course a sorted list with an updated state.. If `list` is `NULLL`, item 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.

Note
  O(log2(n)) comparisons (calls to `func`) average/worst case performance. As said in eina_list_search_sorted_near_list(), lists do not have O(1) access time, so walking to the correct node can be costly, but this version try to minimize that by making it a O(log2(n)) for number small number. After n == 256, it start to add a linear cost again. Consider worst case to be almost O(n) pointer dereference (list walk).

References eina_inlist_append(), eina_inlist_append_relative(), eina_inlist_prepend(), eina_inlist_prepend_relative(), and _Eina_Inlist::next.

Referenced by eldbus_signal_handler_match_extra_vset().

Eina_Inlist* eina_inlist_sort | ( | Eina_Inlist * | head,
|  | Eina_Compare_Cb | func
| ) |  |

Sort a list according to the ordering func will return.

Parameters

  head | The list handle to sort.
  func | A function pointer that can handle comparing the list data nodes.

Returns
  the new head of list.

This function sorts all the elements of `head`. `func` is used to compare two elements of `head`. If `head` 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.
  Worst case is O(n * log2(n)) comparisons (calls to func()). That means that for 1,000,000 list elements, sort will do 20,000,000 comparisons.

Example:

1 typedef struct _Sort_Ex Sort_Ex;
2 struct _Sort_Ex
3 {
4 EINA_INLIST;
5 const char *text;
6 };
7
8 int
9 sort_cb(const Inlist *l1, const Inlist *l2)
10 {
11 const Sort_Ex *x1;
12 const Sort_Ex *x2;
13
14 x1 = EINA_INLIST_CONTAINER_GET(l1, Sort_Ex);
15 x2 = EINA_INLIST_CONTAINER_GET(l2, Sort_Ex);
16
17 return(strcmp(x1->text, x2->text));
18 }
19 extern Eina_Inlist *list;
20
21 list = eina_inlist_sort(list, sort_cb);

References _Eina_Inlist::last, and _Eina_Inlist::next.