[interpreter] Size reduction
[mono.git] / eglib / src / gslist.c
index 4e61e5d9f868ac3ac6e6729b6c4d6389e360b764..5baa297f7386923e50f0b5788c67ec8bda7dd399 100644 (file)
@@ -1,8 +1,9 @@
 /*
  * gslist.c: Singly-linked list implementation
  *
- * Author:
+ * Authors:
  *   Duncan Mak (duncan@novell.com)
+ *   Raja R Harinath (rharinath@novell.com)
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -180,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)
 {
@@ -298,3 +315,48 @@ g_slist_insert_sorted (GSList *list, gpointer data, GCompareFunc func)
        insert_after (prev, data);
        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"
+
+GSList*
+g_slist_sort (GSList *list, GCompareFunc func)
+{
+       if (!list || !list->next)
+               return list;
+       return do_sort (list, func);
+}