GList insert_before variants



posting for review, upcomming patch for glib to implement
gslist/glist insert_before variants:

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/ChangeLog,v
retrieving revision 1.737
diff -u -u -r1.737 ChangeLog
--- ChangeLog	2001/06/28 17:05:10	1.737
+++ ChangeLog	2001/06/30 21:13:20
@@ -1,3 +1,10 @@
+Sat Jun 30 23:14:32 2001  Tim Janik  <timj gtk org>
+
+	* glib/glist.[hc]: added g_list_insert_before().
+
+	* glib/gslist.c (g_slist_insert_before): provide an implementation,
+	prototype was already present...
+
 Thu Jun 28 16:57:44 2001  Tim Janik  <timj gtk org>
 
 	* configure.in (GLIB_MICRO_VERSION): up version number to 1.3.7,
Index: glib/glist.c
===================================================================
RCS file: /cvs/gnome/glib/glib/glist.c,v
retrieving revision 1.25
diff -u -u -r1.25 glist.c
--- glib/glist.c	2001/06/23 13:55:07	1.25
+++ glib/glist.c	2001/06/30 21:13:21
@@ -317,6 +317,56 @@
     return list;
 }
 
+GList*
+g_list_insert_before (GList   *list,
+		      GList   *sibling,
+		      gpointer data)
+{
+  if (!list)
+    {
+      list = g_list_alloc ();
+      list->data = data;
+      g_return_val_if_fail (sibling == NULL, list);
+      return list;
+    }
+  else if (sibling)
+    {
+      GList *node;
+
+      node = g_list_alloc ();
+      node->data = data;
+      if (sibling->prev)
+	{
+	  node->prev = sibling->prev;
+	  node->prev->next = node;
+	  node->next = sibling;
+	  sibling->prev = node;
+	  return list;
+	}
+      else
+	{
+	  node->next = sibling;
+	  sibling->prev = node;
+	  g_return_val_if_fail (sibling == list, node);
+	  return node;
+	}
+    }
+  else
+    {
+      GList *last;
+
+      last = list;
+      while (last->next)
+	last = last->next;
+
+      last->next = g_list_alloc ();
+      last->next->data = data;
+      last->next->prev = last;
+
+      return list;
+    }
+}
+
 GList *
 g_list_concat (GList *list1, GList *list2)
 {
Index: glib/glist.h
===================================================================
RCS file: /cvs/gnome/glib/glib/glist.h,v
retrieving revision 1.6
diff -u -u -r1.6 glist.h
--- glib/glist.h	2001/06/26 16:01:14	1.6
+++ glib/glist.h	2001/06/30 21:13:21
@@ -57,6 +57,9 @@
 GList*   g_list_insert_sorted  (GList            *list,
 				gpointer          data,
 				GCompareFunc      func);
+GList*   g_list_insert_before  (GList            *list,
+				GList            *sibling,
+				gpointer          data);
 GList*   g_list_concat         (GList            *list1,
 				GList            *list2);
 GList*   g_list_remove         (GList            *list,
Index: glib/gslist.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gslist.c,v
retrieving revision 1.23
diff -u -u -r1.23 gslist.c
--- glib/gslist.c	2001/05/03 10:47:31	1.23
+++ glib/gslist.c	2001/06/30 21:13:21
@@ -307,6 +307,45 @@
   return list;
 }
 
+GSList*
+g_slist_insert_before (GSList  *slist,
+		       GSList  *sibling,
+		       gpointer data)
+{
+  if (!slist)
+    {
+      slist = g_slist_alloc ();
+      slist->data = data;
+      g_return_val_if_fail (sibling == NULL, slist);
+      return slist;
+    }
+  else
+    {
+      GSList *node, *last = NULL;
+
+      for (node = slist; node; last = node, node = last->next)
+	if (node == sibling)
+	  break;
+      if (!last)
+	{
+	  node = g_slist_alloc ();
+	  node->data = data;
+	  node->next = slist;
+
+	  return node;
+	}
+      else
+	{
+	  node = g_slist_alloc ();
+	  node->data = data;
+	  node->next = last->next;
+	  last->next = node;
+
+	  return slist;
+	}
+    }
+}
+
 GSList *
 g_slist_concat (GSList *list1, GSList *list2)
 {


---
ciaoTJ





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]