+Fri Nov 13 15:17:34 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glist.c gslist.c glib.h: Added g_list_sort() and
+ g_slist_sort() to merge sort GLists and GSLists.
+ Submitted by Sven Over <sven.over@ob.kamp.net>
+ over a year ago!
+
+ * testglib.c: Test the new sort functions.
+
Wed Nov 11 23:23:22 EST 1998 Jeff Garzik <jgarzik@pobox.com>
* Makefile.am : INCLUDES is the right way to add to CFLAGS, not
Sun Sep 20 18:21:46 1998 Owen Taylor <otaylor@redhat.com>
- * ltconfig.sh: Patch to libtool-1.2b to make --disable-static
+ * ltmain.sh: Patch to libtool-1.2b to make --disable-static
work.
Sun Sep 20 02:09:44 1998 Josh MacDonald <jmacd@axis.hip.berkeley.edu>
+Fri Nov 13 15:17:34 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glist.c gslist.c glib.h: Added g_list_sort() and
+ g_slist_sort() to merge sort GLists and GSLists.
+ Submitted by Sven Over <sven.over@ob.kamp.net>
+ over a year ago!
+
+ * testglib.c: Test the new sort functions.
+
Wed Nov 11 23:23:22 EST 1998 Jeff Garzik <jgarzik@pobox.com>
* Makefile.am : INCLUDES is the right way to add to CFLAGS, not
Sun Sep 20 18:21:46 1998 Owen Taylor <otaylor@redhat.com>
- * ltconfig.sh: Patch to libtool-1.2b to make --disable-static
+ * ltmain.sh: Patch to libtool-1.2b to make --disable-static
work.
Sun Sep 20 02:09:44 1998 Josh MacDonald <jmacd@axis.hip.berkeley.edu>
+Fri Nov 13 15:17:34 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glist.c gslist.c glib.h: Added g_list_sort() and
+ g_slist_sort() to merge sort GLists and GSLists.
+ Submitted by Sven Over <sven.over@ob.kamp.net>
+ over a year ago!
+
+ * testglib.c: Test the new sort functions.
+
Wed Nov 11 23:23:22 EST 1998 Jeff Garzik <jgarzik@pobox.com>
* Makefile.am : INCLUDES is the right way to add to CFLAGS, not
Sun Sep 20 18:21:46 1998 Owen Taylor <otaylor@redhat.com>
- * ltconfig.sh: Patch to libtool-1.2b to make --disable-static
+ * ltmain.sh: Patch to libtool-1.2b to make --disable-static
work.
Sun Sep 20 02:09:44 1998 Josh MacDonald <jmacd@axis.hip.berkeley.edu>
+Fri Nov 13 15:17:34 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glist.c gslist.c glib.h: Added g_list_sort() and
+ g_slist_sort() to merge sort GLists and GSLists.
+ Submitted by Sven Over <sven.over@ob.kamp.net>
+ over a year ago!
+
+ * testglib.c: Test the new sort functions.
+
Wed Nov 11 23:23:22 EST 1998 Jeff Garzik <jgarzik@pobox.com>
* Makefile.am : INCLUDES is the right way to add to CFLAGS, not
Sun Sep 20 18:21:46 1998 Owen Taylor <otaylor@redhat.com>
- * ltconfig.sh: Patch to libtool-1.2b to make --disable-static
+ * ltmain.sh: Patch to libtool-1.2b to make --disable-static
work.
Sun Sep 20 02:09:44 1998 Josh MacDonald <jmacd@axis.hip.berkeley.edu>
+Fri Nov 13 15:17:34 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glist.c gslist.c glib.h: Added g_list_sort() and
+ g_slist_sort() to merge sort GLists and GSLists.
+ Submitted by Sven Over <sven.over@ob.kamp.net>
+ over a year ago!
+
+ * testglib.c: Test the new sort functions.
+
Wed Nov 11 23:23:22 EST 1998 Jeff Garzik <jgarzik@pobox.com>
* Makefile.am : INCLUDES is the right way to add to CFLAGS, not
Sun Sep 20 18:21:46 1998 Owen Taylor <otaylor@redhat.com>
- * ltconfig.sh: Patch to libtool-1.2b to make --disable-static
+ * ltmain.sh: Patch to libtool-1.2b to make --disable-static
work.
Sun Sep 20 02:09:44 1998 Josh MacDonald <jmacd@axis.hip.berkeley.edu>
+Fri Nov 13 15:17:34 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glist.c gslist.c glib.h: Added g_list_sort() and
+ g_slist_sort() to merge sort GLists and GSLists.
+ Submitted by Sven Over <sven.over@ob.kamp.net>
+ over a year ago!
+
+ * testglib.c: Test the new sort functions.
+
Wed Nov 11 23:23:22 EST 1998 Jeff Garzik <jgarzik@pobox.com>
* Makefile.am : INCLUDES is the right way to add to CFLAGS, not
Sun Sep 20 18:21:46 1998 Owen Taylor <otaylor@redhat.com>
- * ltconfig.sh: Patch to libtool-1.2b to make --disable-static
+ * ltmain.sh: Patch to libtool-1.2b to make --disable-static
work.
Sun Sep 20 02:09:44 1998 Josh MacDonald <jmacd@axis.hip.berkeley.edu>
+Fri Nov 13 15:17:34 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glist.c gslist.c glib.h: Added g_list_sort() and
+ g_slist_sort() to merge sort GLists and GSLists.
+ Submitted by Sven Over <sven.over@ob.kamp.net>
+ over a year ago!
+
+ * testglib.c: Test the new sort functions.
+
Wed Nov 11 23:23:22 EST 1998 Jeff Garzik <jgarzik@pobox.com>
* Makefile.am : INCLUDES is the right way to add to CFLAGS, not
Sun Sep 20 18:21:46 1998 Owen Taylor <otaylor@redhat.com>
- * ltconfig.sh: Patch to libtool-1.2b to make --disable-static
+ * ltmain.sh: Patch to libtool-1.2b to make --disable-static
work.
Sun Sep 20 02:09:44 1998 Josh MacDonald <jmacd@axis.hip.berkeley.edu>
+Fri Nov 13 15:17:34 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glist.c gslist.c glib.h: Added g_list_sort() and
+ g_slist_sort() to merge sort GLists and GSLists.
+ Submitted by Sven Over <sven.over@ob.kamp.net>
+ over a year ago!
+
+ * testglib.c: Test the new sort functions.
+
Wed Nov 11 23:23:22 EST 1998 Jeff Garzik <jgarzik@pobox.com>
* Makefile.am : INCLUDES is the right way to add to CFLAGS, not
Sun Sep 20 18:21:46 1998 Owen Taylor <otaylor@redhat.com>
- * ltconfig.sh: Patch to libtool-1.2b to make --disable-static
+ * ltmain.sh: Patch to libtool-1.2b to make --disable-static
work.
Sun Sep 20 02:09:44 1998 Josh MacDonald <jmacd@axis.hip.berkeley.edu>
void g_list_foreach (GList *list,
GFunc func,
gpointer user_data);
+GList* g_list_sort (GList *list,
+ GCompareFunc compare_func);
gpointer g_list_nth_data (GList *list,
guint n);
#define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
void g_slist_foreach (GSList *list,
GFunc func,
gpointer user_data);
+GSList* g_slist_sort (GSList *list,
+ GCompareFunc compare_func);
gpointer g_slist_nth_data (GSList *list,
guint n);
#define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
void g_list_foreach (GList *list,
GFunc func,
gpointer user_data);
+GList* g_list_sort (GList *list,
+ GCompareFunc compare_func);
gpointer g_list_nth_data (GList *list,
guint n);
#define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
void g_slist_foreach (GSList *list,
GFunc func,
gpointer user_data);
+GSList* g_slist_sort (GSList *list,
+ GCompareFunc compare_func);
gpointer g_slist_nth_data (GSList *list,
guint n);
#define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
g_list_free (GList *list)
{
GList *last;
-
+
if (list)
{
last = g_list_last (list);
else
return list;
}
+
+static GList *
+g_list_sort_merge (GList *l1,
+ GList *l2,
+ GCompareFunc compare_func)
+{
+ GList list, *l, *lprev;
+
+ l = &list;
+ lprev = NULL;
+
+ while (l1 && l2)
+ {
+ if (compare_func (l1->data, l2->data) < 0)
+ {
+ l->next = l1;
+ l = l->next;
+ l->prev = lprev;
+ lprev = l;
+ l1 = l1->next;
+ }
+ else
+ {
+ l->next = l2;
+ l = l->next;
+ l->prev = lprev;
+ lprev = l;
+ l2 = l2->next;
+ }
+ }
+ l->next = l1 ? l1 : l2;
+ l->next->prev = l;
+
+ return list.next;
+}
+
+GList*
+g_list_sort (GList *list,
+ GCompareFunc compare_func)
+{
+ GList *l1, *l2;
+
+ if (!list)
+ return NULL;
+ if (!list->next)
+ return list;
+
+ l1 = list;
+ l2 = list->next;
+
+ while ((l2 = l2->next) != NULL)
+ {
+ if ((l2 = l2->next) == NULL)
+ break;
+ l1 = l1->next;
+ }
+ l2 = l1->next;
+ l1->next = NULL;
+
+ return g_list_sort_merge (g_list_sort (list, compare_func),
+ g_list_sort (l2, compare_func),
+ compare_func);
+}
return new_list;
}
}
+
+static GSList*
+g_slist_sort_merge (GSList *l1,
+ GSList *l2,
+ GCompareFunc compare_func)
+{
+ GSList list, *l;
+
+ l=&list;
+
+ while (l1 && l2)
+ {
+ if (compare_func(l1->data,l2->data) < 0)
+ {
+ l=l->next=l1;
+ l1=l1->next;
+ }
+ else
+ {
+ l=l->next=l2;
+ l2=l2->next;
+ }
+ }
+ l->next= l1 ? l1 : l2;
+
+ return list.next;
+}
+
+GSList*
+g_slist_sort (GSList *list,
+ GCompareFunc compare_func)
+{
+ GSList *l1, *l2;
+
+ if (!list)
+ return NULL;
+ if (!list->next)
+ return list;
+
+ l1 = list;
+ l2 = list->next;
+
+ while ((l2 = l2->next) != NULL)
+ {
+ if ((l2 = l2->next) == NULL)
+ break;
+ l1=l1->next;
+ }
+ 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);
+}
g_list_free (GList *list)
{
GList *last;
-
+
if (list)
{
last = g_list_last (list);
else
return list;
}
+
+static GList *
+g_list_sort_merge (GList *l1,
+ GList *l2,
+ GCompareFunc compare_func)
+{
+ GList list, *l, *lprev;
+
+ l = &list;
+ lprev = NULL;
+
+ while (l1 && l2)
+ {
+ if (compare_func (l1->data, l2->data) < 0)
+ {
+ l->next = l1;
+ l = l->next;
+ l->prev = lprev;
+ lprev = l;
+ l1 = l1->next;
+ }
+ else
+ {
+ l->next = l2;
+ l = l->next;
+ l->prev = lprev;
+ lprev = l;
+ l2 = l2->next;
+ }
+ }
+ l->next = l1 ? l1 : l2;
+ l->next->prev = l;
+
+ return list.next;
+}
+
+GList*
+g_list_sort (GList *list,
+ GCompareFunc compare_func)
+{
+ GList *l1, *l2;
+
+ if (!list)
+ return NULL;
+ if (!list->next)
+ return list;
+
+ l1 = list;
+ l2 = list->next;
+
+ while ((l2 = l2->next) != NULL)
+ {
+ if ((l2 = l2->next) == NULL)
+ break;
+ l1 = l1->next;
+ }
+ l2 = l1->next;
+ l1->next = NULL;
+
+ return g_list_sort_merge (g_list_sort (list, compare_func),
+ g_list_sort (l2, compare_func),
+ compare_func);
+}
return new_list;
}
}
+
+static GSList*
+g_slist_sort_merge (GSList *l1,
+ GSList *l2,
+ GCompareFunc compare_func)
+{
+ GSList list, *l;
+
+ l=&list;
+
+ while (l1 && l2)
+ {
+ if (compare_func(l1->data,l2->data) < 0)
+ {
+ l=l->next=l1;
+ l1=l1->next;
+ }
+ else
+ {
+ l=l->next=l2;
+ l2=l2->next;
+ }
+ }
+ l->next= l1 ? l1 : l2;
+
+ return list.next;
+}
+
+GSList*
+g_slist_sort (GSList *list,
+ GCompareFunc compare_func)
+{
+ GSList *l1, *l2;
+
+ if (!list)
+ return NULL;
+ if (!list->next)
+ return list;
+
+ l1 = list;
+ l2 = list->next;
+
+ while ((l2 = l2->next) != NULL)
+ {
+ if ((l2 = l2->next) == NULL)
+ break;
+ l1=l1->next;
+ }
+ 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);
+}
g_error ("Sorted insert failed");
}
+ g_list_free (list);
+ list = NULL;
+
+ for (i = 0; i < 10; i++)
+ list = g_list_prepend (list, &morenums[i]);
+
+ list = g_list_sort (list, my_list_compare_two);
+
+ /*
+ g_print("\n");
+ g_list_foreach (list, my_list_print, NULL);
+ */
+
+ for (i = 0; i < 10; i++)
+ {
+ t = g_list_nth (list, i);
+ if (*((gint*) t->data) != (9 - i))
+ g_error ("Merge sort failed");
+ }
+
g_list_free (list);
g_print ("ok\n");
g_slist_foreach (slist, my_list_print, NULL);
*/
+ for (i = 0; i < 10; i++)
+ {
+ st = g_slist_nth (slist, i);
+ if (*((gint*) st->data) != (9 - i))
+ g_error("Sorted insert failed");
+ }
+
+ g_slist_free(slist);
+ slist = NULL;
+
+ for (i = 0; i < 10; i++)
+ slist = g_slist_prepend (slist, &morenums[i]);
+
+ slist = g_slist_sort (slist, my_list_compare_two);
+
+ /*
+ g_print("\n");
+ g_slist_foreach (slist, my_list_print, NULL);
+ */
+
for (i = 0; i < 10; i++)
{
st = g_slist_nth (slist, i);
g_error ("Sorted insert failed");
}
+ g_list_free (list);
+ list = NULL;
+
+ for (i = 0; i < 10; i++)
+ list = g_list_prepend (list, &morenums[i]);
+
+ list = g_list_sort (list, my_list_compare_two);
+
+ /*
+ g_print("\n");
+ g_list_foreach (list, my_list_print, NULL);
+ */
+
+ for (i = 0; i < 10; i++)
+ {
+ t = g_list_nth (list, i);
+ if (*((gint*) t->data) != (9 - i))
+ g_error ("Merge sort failed");
+ }
+
g_list_free (list);
g_print ("ok\n");
g_slist_foreach (slist, my_list_print, NULL);
*/
+ for (i = 0; i < 10; i++)
+ {
+ st = g_slist_nth (slist, i);
+ if (*((gint*) st->data) != (9 - i))
+ g_error("Sorted insert failed");
+ }
+
+ g_slist_free(slist);
+ slist = NULL;
+
+ for (i = 0; i < 10; i++)
+ slist = g_slist_prepend (slist, &morenums[i]);
+
+ slist = g_slist_sort (slist, my_list_compare_two);
+
+ /*
+ g_print("\n");
+ g_slist_foreach (slist, my_list_print, NULL);
+ */
+
for (i = 0; i < 10; i++)
{
st = g_slist_nth (slist, i);