inlist: add count.
authorbarbieri <barbieri>
Fri, 13 Mar 2009 11:32:56 +0000 (11:32 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 13 Mar 2009 11:32:56 +0000 (11:32 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@39465 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/include/eina_inlist.h
src/lib/eina_inlist.c

index b434911..cbcd80d 100644 (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;
index 463579a..29d5900 100644 (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)
 {