Merge pull request #3121 from lambdageek/dev/managed-init_message
[mono.git] / eglib / src / gslist.c
index f0b2368fbf7e8989770a54ebe9a591dc93213067..5baa297f7386923e50f0b5788c67ec8bda7dd399 100644 (file)
@@ -181,6 +181,22 @@ g_slist_find (GSList *list, gconstpointer data)
        return list;
 }
 
+GSList *
+g_slist_find_custom (GSList *list, gconstpointer data, GCompareFunc func)
+{
+       if (!func)
+               return NULL;
+       
+       while (list) {
+               if (func (list->data, data) == 0)
+                       return list;
+               
+               list = list->next;
+       }
+       
+       return NULL;
+}
+
 guint
 g_slist_length (GSList *list)
 {
@@ -300,6 +316,40 @@ g_slist_insert_sorted (GSList *list, gpointer data, GCompareFunc func)
        return list;
 }
 
+gint
+g_slist_index (GSList *list, gconstpointer data)
+{
+       gint index = 0;
+       
+       while (list) {
+               if (list->data == data)
+                       return index;
+               
+               index++;
+               list = list->next;
+       }
+       
+       return -1;
+}
+
+GSList*
+g_slist_nth (GSList *list, guint n)
+{
+       for (; list; list = list->next) {
+               if (n == 0)
+                       break;
+               n--;
+       }
+       return list;
+}
+
+gpointer
+g_slist_nth_data (GSList *list, guint n)
+{
+       GSList *node = g_slist_nth (list, n);
+       return node ? node->data : NULL;
+}
+
 typedef GSList list_node;
 #include "sort.frag.h"
 
@@ -310,14 +360,3 @@ g_slist_sort (GSList *list, GCompareFunc func)
                return list;
        return do_sort (list, func);
 }
-
-gpointer
-g_slist_nth_data (GSList *list, guint n)
-{
-       while (n-- && list != NULL){
-               list = list->next;
-       }
-       if (list)
-               return list->data;
-       return NULL;
-}