#ifndef EINA_LIST_INLINE_H_
#define EINA_LIST_INLINE_H_
-/**
- * @addtogroup Eina_List_Group List
- *
- * @brief These functions provide list management.
- *
- * @{
- */
-
-/**
- * @brief Get the last list node in the list.
- *
- * @param list The list to get the last list node from.
- * @return The last list node in the list.
- *
- * This function returns the last list node in the list @p list. If
- * @p list is @c NULL or empty, @c NULL is returned.
- *
- * This is a order-1 operation (it takes the same short time
- * regardless of the length of the list).
- */
static inline Eina_List *
eina_list_last(const Eina_List *list)
{
return list->accounting->last;
}
-/**
- * @brief Get the next list node after the specified list node.
- *
- * @param list The list node to get the next list node from
- * @return The next list node on success, @c NULL otherwise.
- *
- * This function returns the next list node after the current one in
- * @p list. It is equivalent to list->next. If @p list is @c NULL or
- * if no next list node exists, it returns @c NULL.
- */
static inline Eina_List *
eina_list_next(const Eina_List *list)
{
return list->next;
}
-/**
- * @brief Get the previous list node before the specified list node.
- *
- * @param list The list node to get the previous list node from.
- * @return The previous list node o success, @c NULL otherwise.
- * if no previous list node exists
- *
- * This function returns the previous list node before the current one
- * in @p list. It is equivalent to list->prev. If @p list is @c NULL or
- * if no previous list node exists, it returns @c NULL.
- */
static inline Eina_List *
eina_list_prev(const Eina_List *list)
{
return list->prev;
}
-/**
- * @brief Get the list node data member.
- *
- * @param list The list node to get the data member of.
- * @return The data member from the list node.
- *
- * This function returns the data member of the specified list node @p
- * list. It is equivalent to list->data. If @p list is @c NULL, this
- * function returns @c NULL.
- */
static inline void *
eina_list_data_get(const Eina_List *list)
{
return list->data;
}
-/**
- * @brief Set the list node data member.
- *
- * @param list The list node to get the data member of.
- * @param data The data member to the list node.
- * @return The previous data value.
- *
- * This function set the data member @p data of the specified list node
- * @p list. It returns the previous data of the node. If @p list is
- * @c NULL, this function returns @c NULL.
- */
static inline void *
eina_list_data_set(Eina_List *list, const void *data)
{
return tmp;
}
-/**
- * @brief Get the count of the number of items in a list.
- *
- * @param list The list whose count to return.
- * @return The number of members in the list.
- *
- * This function returns how many members @p list contains. If the
- * list is @c NULL, 0 is returned.
- *
- * NB: This is an order-1 operation and takes the same time regardless
- * of the length of the list.
- */
static inline unsigned int
eina_list_count(const Eina_List *list)
{
return list->accounting->count;
}
-/**
- * @}
- */
-
#endif /* EINA_LIST_INLINE_H_ */
* To replace an element in the list it is not necessary to remove it and then
* add with the new value, it is possible to just change the value of a node:
* @until aquarius
- *
+ *
+ * We will now take a peek to see if the list still has the right number of
+ * elements:
+ * @until printf
+ *
* Now that the list is in alphabetical order let's create a copy of it in
* reverse order and print every element to see if worked as expected:
* @until iterator_free
* @skip #include
* @until Sharon
*
- * The most common way of iterating over a list:
+ * This time we are going to iterate over our list in a different way:
+ * @until printf
+ *
+ * And now we are going to iterate over the list backwards:
* @until printf
*
* And now we need to free up the memory allocated during creation of the list:
* @ref eina_list_data_find), the @a list versions of these functions operate
* on @ref Eina_List nodes.
*
+ * @warning You must @b always use the pointer to the first element of the list
+ * as the list!
+ * @warning You must @b never use a pointer to an element in the middle of the
+ * list as the list!
+ *
* Here are some examples of @ref Eina_List usage:
* @li @ref list_01_example_page
* @li @ref list_02_example_page
* exit(-1);
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list(or NULL).
*/
EAPI Eina_List *eina_list_append(Eina_List *list, const void *data) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* exit(-1);
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_prepend(Eina_List *list, const void *data) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* exit(-1);
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_append_relative(Eina_List *list, const void *data, const void *relative) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* 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.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_append_relative_list(Eina_List *list, const void *data, Eina_List *relative) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* exit(-1);
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_prepend_relative(Eina_List *list, const void *data, const void *relative) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* 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.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_prepend_relative_list(Eina_List *list, const void *data, Eina_List *relative) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* 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).
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_sorted_insert(Eina_List *list, Eina_Compare_Cb func, const void *data) EINA_ARG_NONNULL(2, 3) EINA_WARN_UNUSED_RESULT;
* @p list is @c NULL, @c NULL is returned, otherwise a new list
* pointer that should be used in place of the one passed to this
* function.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_remove(Eina_List *list, const void *data) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* }
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_remove_list(Eina_List *list, Eina_List *remove_list) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* }
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_promote_list(Eina_List *list, Eina_List *move_list) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* }
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_demote_list(Eina_List *list, Eina_List *move_list);
* printf("Found member %p\n", my_data);
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI void *eina_list_data_find(const Eina_List *list, const void *data) EINA_PURE EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* first member whose data pointer is @p data. If it is found, the
* list node containing the specified member is returned, otherwise
* @c NULL is returned.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_data_find_list(const Eina_List *list, const void *data) EINA_PURE EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
* This function is a shortcut for doing the following:
* to = eina_list_append(to, data);
* from = eina_list_remove(from, data);
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_Bool eina_list_move(Eina_List **to, Eina_List **from, void *data);
* This function is a shortcut for doing the following:
* to = eina_list_append(to, data->data);
* from = eina_list_remove_list(from, data);
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_Bool eina_list_move_list(Eina_List **to, Eina_List **from, Eina_List *data);
* the @p list. The first element in the array is element number 0. If
* the element number @p n does not exist, @c NULL is
* returned. Otherwise, the data of the found element is returned.
+ *
+ * @note Worst case is O(n).
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI void *eina_list_nth(const Eina_List *list, unsigned int n) EINA_PURE EINA_WARN_UNUSED_RESULT;
* greater than the count of elements in @p list minus 1, @c NULL is
* returned. Otherwise the list node stored in the numbered element is
* returned.
+ *
+ * @note Worst case is O(n).
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_nth_list(const Eina_List *list, unsigned int n) EINA_PURE EINA_WARN_UNUSED_RESULT;
* @note @b in-place: this will change the given list, so you should
* now point to the new list head that is returned by this function.
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @see eina_list_reverse_clone()
* @see eina_list_iterator_reversed_new()
*/
* @note @b copy: this will copy the list and you should then
* eina_list_free() when it is not required anymore.
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @see eina_list_reverse()
* @see eina_list_clone()
*/
* @note @b copy: this will copy the list and you should then
* eina_list_free() when it is not required anymore.
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @see eina_list_reverse_clone()
*/
EAPI Eina_List *eina_list_clone(const Eina_List *list) EINA_WARN_UNUSED_RESULT;
*
* list = eina_list_sort(list, eina_list_count(list), sort_cb);
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_sort(Eina_List *list, unsigned int size, Eina_Compare_Cb func) EINA_ARG_NONNULL(3) EINA_WARN_UNUSED_RESULT;
* @note merge cost is O(n), being @b n the size of the smallest
* list. This is due the need to fix accounting of that segment,
* making count and last access O(1).
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_merge(Eina_List *left, Eina_List *right) EINA_WARN_UNUSED_RESULT;
*
* list = eina_list_sorted_merge(sorted1, sorted2, sort_cb);
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_sorted_merge(Eina_List *left, Eina_List *right, Eina_Compare_Cb func) EINA_ARG_NONNULL(3) EINA_WARN_UNUSED_RESULT;
*
* list does not exist anymore after the split.
*
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_List *eina_list_split_list(Eina_List *list, Eina_List *relative, Eina_List **right) EINA_WARN_UNUSED_RESULT;
* than requested data, it is less than 0 and if it's bigger it's
* greater than 0. It is the last value returned by func().
* @return the nearest node, NULL if not found.
+ *
+ * This function searches for a node containing @p data as it's data in @p list,
+ * if such a node exists it will be returned and @p result_cmp will be @p 0. If
+ * the data of no node in @p list is equal to @p data, the node with the nearest
+ * value to that will be returned and @p result_cmp will be the return value of
+ * @p func with @p data and the returned node's data as arguments.
*
* This function is useful for inserting an element in the list only in case it
* isn't already present in the list, the naive way of doing this would be:
* the correct node can be costly, consider worst case to be almost
* O(n) pointer dereference (list walk).
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @see eina_list_search_sorted_list()
* @see eina_list_sort()
* @see eina_list_sorted_merge()
* time, so walking to the correct node can be costly, consider worst
* case to be almost O(n) pointer dereference (list walk).
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @see eina_list_search_sorted()
* @see eina_list_sort()
* @see eina_list_sorted_merge()
* time, so walking to the correct node can be costly, consider worst
* case to be almost O(n) pointer dereference (list walk).
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @see eina_list_search_sorted_list()
* @see eina_list_sort()
* @see eina_list_sorted_merge()
* that is for 1,000,000 elements list it may walk and compare
* 1,000,000 nodes.
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @see eina_list_search_sorted_list()
* @see eina_list_search_unsorted()
*/
* that is for 1,000,000 elements list it may walk and compare
* 1,000,000 nodes.
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @see eina_list_search_sorted()
* @see eina_list_search_unsorted_list()
*/
EAPI void *eina_list_search_unsorted(const Eina_List *list, Eina_Compare_Cb func, const void *data);
+/**
+ * @brief Get the last list node in the list.
+ *
+ * @param list The list to get the last list node from.
+ * @return The last list node in the list.
+ *
+ * This function returns the last list node in the list @p list. If
+ * @p list is @c NULL or empty, @c NULL is returned.
+ *
+ * This is a order-1 operation (it takes the same short time
+ * regardless of the length of the list).
+ *
+ * @warning @p list must be a pointer to the first element of the list.
+ */
static inline Eina_List *eina_list_last(const Eina_List *list) EINA_PURE EINA_WARN_UNUSED_RESULT;
+/**
+ * @brief Get the next list node after the specified list node.
+ *
+ * @param list The list node to get the next list node from
+ * @return The next list node on success, @c NULL otherwise.
+ *
+ * This function returns the next list node after the current one in
+ * @p list. It is equivalent to list->next. If @p list is @c NULL or
+ * if no next list node exists, it returns @c NULL.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
+ */
static inline Eina_List *eina_list_next(const Eina_List *list) EINA_PURE EINA_WARN_UNUSED_RESULT;
+/**
+ * @brief Get the previous list node before the specified list node.
+ *
+ * @param list The list node to get the previous list node from.
+ * @return The previous list node o success, @c NULL otherwise.
+ * if no previous list node exists
+ *
+ * This function returns the previous list node before the current one
+ * in @p list. It is equivalent to list->prev. If @p list is @c NULL or
+ * if no previous list node exists, it returns @c NULL.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
+ */
static inline Eina_List *eina_list_prev(const Eina_List *list) EINA_PURE EINA_WARN_UNUSED_RESULT;
+/**
+ * @brief Get the list node data member.
+ *
+ * @param list The list node to get the data member of.
+ * @return The data member from the list node.
+ *
+ * This function returns the data member of the specified list node @p
+ * list. It is equivalent to list->data. If @p list is @c NULL, this
+ * function returns @c NULL.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
+ */
static inline void *eina_list_data_get(const Eina_List *list) EINA_PURE EINA_WARN_UNUSED_RESULT;
+/**
+ * @brief Set the list node data member.
+ *
+ * @param list The list node to get the data member of.
+ * @param data The data member to the list node.
+ * @return The previous data value.
+ *
+ * This function set the data member @p data of the specified list node
+ * @p list. It returns the previous data of the node. If @p list is
+ * @c NULL, this function returns @c NULL.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
+ */
+static inline void *eina_list_data_set(Eina_List *list, const void *data) EINA_PURE;
+
+/**
+ * @brief Get the count of the number of items in a list.
+ *
+ * @param list The list whose count to return.
+ * @return The number of members in the list.
+ *
+ * This function returns how many members @p list contains. If the
+ * list is @c NULL, 0 is returned.
+ *
+ * NB: This is an order-1 operation and takes the same time regardless
+ * of the length of the list.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
+ */
static inline unsigned int eina_list_count(const Eina_List *list) EINA_PURE;
* #EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is
* returned.
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @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!
* #EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is
* returned.
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @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!
* 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.
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
EAPI Eina_Accessor *eina_list_accessor_new(const Eina_List *list) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
* a list, since it iterates over the list twice.
* For an optimized algorithm, use EINA_LIST_FREE().
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @warning Be careful when deleting list nodes.
* If you remove the current node and continue iterating,
* the code will fail because the macro will not be able
* a list, since it iterates over the list twice.
* For an optimized algorithm, use EINA_LIST_FREE().
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @warning Be careful when deleting list nodes.
* If you remove the current node and continue iterating,
* the code will fail because the macro will not be able
* list = eina_list_remove_list(list, l);
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
#define EINA_LIST_FOREACH_SAFE(list, l, l_next, data) \
for (l = list, \
* list = eina_list_remove_list(list, l);
* }
* @endcode
+ *
+ * @warning @p list must be a pointer to the first element of the list.
*/
#define EINA_LIST_REVERSE_FOREACH_SAFE(list, l, l_prev, data) \
for (l = eina_list_last(list), \
* free(data);
* @endcode
*
+ * @warning @p list must be a pointer to the first element of the list.
+ *
* @see eina_list_free()
*/
#define EINA_LIST_FREE(list, data) \