]> Pileus Git - ~andy/gtk/commitdiff
Someone has to make SOME backwards incompatible changes sometime. I
authorElliot Lee <sopwith@src.gnome.org>
Tue, 28 Apr 1998 00:24:34 +0000 (00:24 +0000)
committerElliot Lee <sopwith@src.gnome.org>
Tue, 28 Apr 1998 00:24:34 +0000 (00:24 +0000)
Someone has to make SOME backwards incompatible changes sometime. I
switched around the prev & next pointers in GList.

not. (Would this change make any functional difference? Discuss in a five
page paper. :-)

Actually, added g_list_position() - inverse of g_list_nth()

glib/ChangeLog
glib/glib.h
glib/glist.c
glib/testglib.c

index 2ab8ab1f9b2995057906f0d6432df383461d4d4b..67bfd738d42e9d8ae3761e5c61f64496de309471 100644 (file)
@@ -1,3 +1,9 @@
+1998-04-27  Elliot Lee  <sopwith@cuc.ml.org>
+
+       * glist.c (g_list_position): New function to find the position of
+       a link in a list - should be the inverse of g_list_nth(), but
+       haven't tested it so poof.
+
 Tue Apr  7 19:36:48 1998  Owen Taylor  <owt1@cornell.edu>
 
        * gutils.c (g_direct_compare): Removed, because that's what
index bc6354199725eab105800896b95008c2157618ee..5fa93487b24be4b40735d164f3f0769096dfed23 100644 (file)
@@ -445,6 +445,8 @@ GList* g_list_remove_link (GList     *list,
 GList* g_list_reverse    (GList     *list);
 GList* g_list_nth        (GList     *list,
                           guint      n);
+gint   g_list_position    (GList     *list,
+                          GList     *link);
 GList* g_list_find       (GList     *list,
                           gpointer   data);
 GList* g_list_last       (GList     *list);
index 70a97ea2db4664f787c1be1ced61f79bf48c9e93..fffe0ed292fce356209d97958cb9893f59c2c2ce 100644 (file)
@@ -300,6 +300,21 @@ g_list_nth (GList *list,
   return list;
 }
 
+gint
+g_list_position (GList     *list,
+                GList     *link)
+{
+  gint nth;
+  GList *curlink;
+  for(nth = 0, curlink = list; curlink; curlink = g_list_next(curlink), nth++)
+    {
+       if(curlink == link) return nth;
+    }
+
+  return -1;
+}
+
+
 GList*
 g_list_find (GList    *list,
             gpointer  data)
index d4bd85a530781ea91ad703a81c54c180c9eb6cf7..95ecd4371978db9e0d15b8431c1f5bababa034ab 100644 (file)
@@ -126,6 +126,10 @@ main (int   argc,
        g_error ("Regular insert failed");
     }
 
+  for (i = 0; i < 10; i++)
+    if(g_list_position(list, g_list_nth (list, i)) != i)
+      g_error("g_list_position does not seem to be the inverse of g_list_nth\n");
+
   g_list_free (list);
   list = NULL;