Added g_s?list_find_custom functions to allow user to specify a

Added g_s?list_find_custom functions to allow user to specify a
GCompareFunc to determine whether a node matches or not.

If you have a better idea for naming the functions, please, make it so! :)
This commit is contained in:
Elliot Lee 1998-06-07 20:18:21 +00:00
parent 8725269e0d
commit a0d3a674d0
3 changed files with 35 additions and 0 deletions

View File

@ -531,6 +531,9 @@ GList* g_list_nth (GList *list,
guint n);
GList* g_list_find (GList *list,
gpointer data);
GList *g_list_find_custom (GList *list,
gpointer data,
GCompareFunc func);
gint g_list_position (GList *list,
GList *link);
gint g_list_index (GList *list,
@ -574,6 +577,9 @@ GSList* g_slist_nth (GSList *list,
guint n);
GSList* g_slist_find (GSList *list,
gpointer data);
GSList *g_slist_find_custom (GSList *list,
gpointer data,
GCompareFunc func);
gint g_slist_position (GSList *list,
GSList *link);
gint g_slist_index (GSList *list,

View File

@ -324,6 +324,21 @@ g_list_find (GList *list,
return list;
}
GList *
g_list_find_custom(GList *list, gpointer data, GCompareFunc func)
{
if(!func) return g_list_find(list, data);
while (list)
{
if ( !((*func)(list->data, data)) ) break;
list = list->next;
}
return list;
}
gint
g_list_position (GList *list,
GList *link)

View File

@ -313,6 +313,20 @@ g_slist_find (GSList *list,
return list;
}
GSList *
g_slist_find_custom(GSList *list, gpointer data, GCompareFunc func)
{
if(!func) return g_slist_find(list, data);
while (list)
{
if ( !((*func)(list->data, data)) ) break;
list = list->next;
}
return list;
}
gint
g_slist_position (GSList *list,
GSList *link)