inlist: add count.

SVN revision: 39465
This commit is contained in:
Gustavo Sverzut Barbieri 2009-03-13 11:32:56 +00:00
parent 739db97356
commit 750bdfce3d
2 changed files with 26 additions and 0 deletions

View File

@ -47,6 +47,7 @@ EAPI Eina_Inlist * eina_inlist_remove(Eina_Inlist *in_list, Eina_Inlist *in_item
EAPI Eina_Inlist * eina_inlist_find(Eina_Inlist *in_list, Eina_Inlist *in_item) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
EAPI Eina_Inlist * eina_inlist_promote(Eina_Inlist *list, Eina_Inlist *item) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
EAPI Eina_Inlist * eina_inlist_demote(Eina_Inlist *list, Eina_Inlist *item) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
EAPI unsigned int eina_inlist_count(const Eina_Inlist *list) EINA_WARN_UNUSED_RESULT;
EAPI Eina_Iterator *eina_inlist_iterator_new(const Eina_Inlist *in_list) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
EAPI Eina_Accessor *eina_inlist_accessor_new(const Eina_Inlist *in_list) EINA_MALLOC EINA_WARN_UNUSED_RESULT;

View File

@ -347,6 +347,31 @@ eina_inlist_find(Eina_Inlist *list, Eina_Inlist *item)
return NULL;
}
/**
* @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.
*
* @warning This is an order-N operation and so the time will depend
* on the number of elements on the list, that is, it might become
* slow for big lists!
*/
EAPI unsigned int
eina_inlist_count(const Eina_Inlist *list)
{
const Eina_Inlist *l;
unsigned int i = 0;
for (l = list; l; l = l->next)
i++;
return i;
}
EAPI Eina_Iterator *
eina_inlist_iterator_new(const Eina_Inlist *list)
{