X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=eglib%2Fsrc%2Fglist.c;h=882fda48ec9b75772bd8f780d2f1fbef9266ab54;hb=323f0816f4feb4685010f41aa1d67c3f2f3976cc;hp=596305b3af23962e7fa2bf9687e0c5bca9bd73a2;hpb=bcf91169e5bfbc9904faf590ebc83f9e5bdbaf45;p=mono.git diff --git a/eglib/src/glist.c b/eglib/src/glist.c index 596305b3af2..882fda48ec9 100644 --- a/eglib/src/glist.c +++ b/eglib/src/glist.c @@ -1,8 +1,9 @@ /* * glist.c: Doubly-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 @@ -124,6 +125,25 @@ g_list_remove (GList *list, gconstpointer data) return list; } +GList* +g_list_remove_all (GList *list, gconstpointer data) +{ + GList *current = g_list_find (list, data); + + if (!current) + return list; + + while (current) { + if (current == list) + list = list->next; + g_list_free_1 (disconnect_node (current)); + + current = g_list_find (list, data); + } + + return list; +} + GList* g_list_remove_link (GList *list, GList *link) { @@ -159,6 +179,22 @@ g_list_find (GList *list, gconstpointer data) return NULL; } +GList* +g_list_find_custom (GList *list, gconstpointer data, GCompareFunc func) +{ + if (!func) + return NULL; + + while (list) { + if (func (list->data, data) == 0) + return list; + + list = list->next; + } + + return NULL; +} + GList* g_list_reverse (GList *list) { @@ -204,7 +240,8 @@ g_list_insert_sorted (GList *list, gpointer data, GCompareFunc func) { GList *prev = NULL; GList *current; - + GList *node; + if (!func) return list; @@ -215,7 +252,7 @@ g_list_insert_sorted (GList *list, gpointer data, GCompareFunc func) prev = current; } - GList *node = new_node (prev, data, current); + node = new_node (prev, data, current); return list == current ? node : list; } @@ -288,3 +325,21 @@ g_list_copy (GList *list) return copy; } +typedef GList list_node; +#include "sort.frag.h" + +GList* +g_list_sort (GList *list, GCompareFunc func) +{ + GList *current; + if (!list || !list->next) + return list; + list = do_sort (list, func); + + /* Fixup: do_sort doesn't update 'prev' pointers */ + list->prev = NULL; + for (current = list; current->next; current = current->next) + current->next->prev = current; + + return list; +}