summaryrefslogtreecommitdiff
path: root/glib/gslist.c
diff options
context:
space:
mode:
authorJonathan Blandford <jrb@redhat.com>2000-11-20 23:59:32 +0000
committerJonathan Blandford <jrb@src.gnome.org>2000-11-20 23:59:32 +0000
commit2645aaf59c540e25915da43eb1cb7fff6f445e6d (patch)
tree40c662781877308f8de470a4fc469e34a1a9af42 /glib/gslist.c
parent40d62d0dd7ba5d5cc9dd00beb72599535f84ae8a (diff)
downloadglib-2645aaf59c540e25915da43eb1cb7fff6f445e6d.tar.gz
Patch from David Benson <daveb@idealab.com> to add user_data support to
Mon Nov 20 18:55:17 2000 Jonathan Blandford <jrb@redhat.com> * gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add user_data support to gtree functions. Mon Nov 13 18:35:52 2000 Jonathan Blandford <jrb@redhat.com> * gtypes.h (GCompareFuncData): new func type to let you use user data when comparing nodes. * gslist.c (g_list_sort_with_data): new function to sort with user_data. * glist.c (g_list_sort_with_data): new function to sort with user_data. * garray.[ch]: Added convenience functions to sort arrays.
Diffstat (limited to 'glib/gslist.c')
-rw-r--r--glib/gslist.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/glib/gslist.c b/glib/gslist.c
index daa182278..d8cc6996a 100644
--- a/glib/gslist.c
+++ b/glib/gslist.c
@@ -580,18 +580,26 @@ g_slist_insert_sorted (GSList *list,
}
}
-static GSList*
-g_slist_sort_merge (GSList *l1,
- GSList *l2,
- GCompareFunc compare_func)
+static GSList *
+g_slist_sort_merge (GSList *l1,
+ GSList *l2,
+ GFunc compare_func,
+ gboolean use_data,
+ gpointer user_data)
{
GSList list, *l;
+ gint cmp;
l=&list;
while (l1 && l2)
{
- if (compare_func(l1->data,l2->data) < 0)
+ if (use_data)
+ cmp = ((GCompareFuncData) compare_func) (l1->data, l2->data, user_data);
+ else
+ cmp = ((GCompareFunc) compare_func) (l1->data, l2->data);
+
+ if (cmp <= 0)
{
l=l->next=l1;
l1=l1->next;
@@ -607,9 +615,11 @@ g_slist_sort_merge (GSList *l1,
return list.next;
}
-GSList*
-g_slist_sort (GSList *list,
- GCompareFunc compare_func)
+static GSList *
+g_slist_sort_real (GSList *list,
+ GFunc compare_func,
+ gboolean use_data,
+ gpointer user_data)
{
GSList *l1, *l2;
@@ -630,7 +640,24 @@ g_slist_sort (GSList *list,
l2 = l1->next;
l1->next = NULL;
- return g_slist_sort_merge (g_slist_sort (list, compare_func),
- g_slist_sort (l2, compare_func),
- compare_func);
+ return g_slist_sort_merge (g_slist_sort_real (list, compare_func, use_data, user_data),
+ g_slist_sort_real (l2, compare_func, use_data, user_data),
+ compare_func,
+ use_data,
+ user_data);
+}
+
+GSList *
+g_slist_sort (GSList *list,
+ GCompareFunc compare_func)
+{
+ return g_slist_sort_real (list, (GFunc) compare_func, FALSE, NULL);
+}
+
+GSList *
+g_slist_sort_with_data (GSList *list,
+ GCompareFuncData compare_func,
+ gpointer user_data)
+{
+ return g_slist_sort_real (list, (GFunc) compare_func, TRUE, user_data);
}