New functions to remove a range of elements from an array. (#94879, Nalin
authorMatthias Clasen <maclas@gmx.de>
Sat, 26 Jul 2003 08:03:16 +0000 (08:03 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sat, 26 Jul 2003 08:03:16 +0000 (08:03 +0000)
2003-07-26  Matthias Clasen  <maclas@gmx.de>

* glib/garray.h:
* glib/garray.c (g_{,byte,pointer}_remove_range): New functions to remove a range of elements
from an array.  (#94879, Nalin Dahyabhai)

13 files changed:
ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/glib/glib-sections.txt
docs/reference/glib/tmpl/arrays.sgml
docs/reference/glib/tmpl/arrays_byte.sgml
docs/reference/glib/tmpl/arrays_pointer.sgml
glib/garray.c
glib/garray.h

index c6e1ce3bb067c0edfeb37ea6a764d5d9c193af4e..83b3d8f66d7546d9fab87da61e8550f487517d7d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2003-07-26  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/garray.h: 
+       * glib/garray.c (g_{,byte,pointer}_remove_range): New functions to remove a range of elements
+       from an array.  (#94879, Nalin Dahyabhai)
+
        * glib/gmessages.c (g_logv): Remove the 1024 char limit in the common (non-recursive)
        case.
 
index c6e1ce3bb067c0edfeb37ea6a764d5d9c193af4e..83b3d8f66d7546d9fab87da61e8550f487517d7d 100644 (file)
@@ -1,5 +1,9 @@
 2003-07-26  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/garray.h: 
+       * glib/garray.c (g_{,byte,pointer}_remove_range): New functions to remove a range of elements
+       from an array.  (#94879, Nalin Dahyabhai)
+
        * glib/gmessages.c (g_logv): Remove the 1024 char limit in the common (non-recursive)
        case.
 
index c6e1ce3bb067c0edfeb37ea6a764d5d9c193af4e..83b3d8f66d7546d9fab87da61e8550f487517d7d 100644 (file)
@@ -1,5 +1,9 @@
 2003-07-26  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/garray.h: 
+       * glib/garray.c (g_{,byte,pointer}_remove_range): New functions to remove a range of elements
+       from an array.  (#94879, Nalin Dahyabhai)
+
        * glib/gmessages.c (g_logv): Remove the 1024 char limit in the common (non-recursive)
        case.
 
index c6e1ce3bb067c0edfeb37ea6a764d5d9c193af4e..83b3d8f66d7546d9fab87da61e8550f487517d7d 100644 (file)
@@ -1,5 +1,9 @@
 2003-07-26  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/garray.h: 
+       * glib/garray.c (g_{,byte,pointer}_remove_range): New functions to remove a range of elements
+       from an array.  (#94879, Nalin Dahyabhai)
+
        * glib/gmessages.c (g_logv): Remove the 1024 char limit in the common (non-recursive)
        case.
 
index c6e1ce3bb067c0edfeb37ea6a764d5d9c193af4e..83b3d8f66d7546d9fab87da61e8550f487517d7d 100644 (file)
@@ -1,5 +1,9 @@
 2003-07-26  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/garray.h: 
+       * glib/garray.c (g_{,byte,pointer}_remove_range): New functions to remove a range of elements
+       from an array.  (#94879, Nalin Dahyabhai)
+
        * glib/gmessages.c (g_logv): Remove the 1024 char limit in the common (non-recursive)
        case.
 
index c6e1ce3bb067c0edfeb37ea6a764d5d9c193af4e..83b3d8f66d7546d9fab87da61e8550f487517d7d 100644 (file)
@@ -1,5 +1,9 @@
 2003-07-26  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/garray.h: 
+       * glib/garray.c (g_{,byte,pointer}_remove_range): New functions to remove a range of elements
+       from an array.  (#94879, Nalin Dahyabhai)
+
        * glib/gmessages.c (g_logv): Remove the 1024 char limit in the common (non-recursive)
        case.
 
index bde27d2148c7b8194781f2a01e816542c928ab99..aa8474e0211c658668a3f59bde78e01e3e025985 100644 (file)
@@ -1,5 +1,10 @@
 2003-07-26  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/tmpl/arrays.sgml: 
+       * glib/tmpl/arrays_byte.sgml: 
+       * glib/tmpl/arrays_pointer.sgml: 
+       * glib/glib-sections.txt: Add g_{,byte,pointer}_array_remove_range.  (#94879, Nalin Dahyabhai)
+
        * glib/tmpl/messages.sgml: Remove the note about the message length restriction.
 
 2003-07-24  Matthias Clasen  <maclas@gmx.de>
index b50e218fb93bc27de9f6e6e25fc2a464a574fc39..06ec3525498a7bbab34d755efba99bb7bb0dfe69 100644 (file)
@@ -1588,6 +1588,7 @@ g_array_insert_val
 g_array_insert_vals
 g_array_remove_index
 g_array_remove_index_fast
+g_array_remove_range
 g_array_sort
 g_array_sort_with_data
 g_array_index
@@ -1606,6 +1607,7 @@ g_ptr_array_remove
 g_ptr_array_remove_index
 g_ptr_array_remove_fast
 g_ptr_array_remove_index_fast
+g_ptr_array_remove_range
 g_ptr_array_sort
 g_ptr_array_sort_with_data
 g_ptr_array_set_size
@@ -1624,6 +1626,7 @@ g_byte_array_append
 g_byte_array_prepend
 g_byte_array_remove_index
 g_byte_array_remove_index_fast
+g_byte_array_remove_range
 g_byte_array_sort
 g_byte_array_sort_with_data
 g_byte_array_set_size
index 4fefede5cc5cbd69fd10745cde0943f70f6575ff..57ad5f936464f82d3f003cd665fdddb834cb4ada 100644 (file)
@@ -212,9 +212,22 @@ g_array_remove_index().
 @Returns: the #GArray.
 
 
+<!-- ##### FUNCTION g_array_remove_range ##### -->
+<para>
+Removes the given number of elements starting at the given index from a
+#GArray.  The following elements are moved to close the gap.
+</para>
+
+@array: a @GArray.
+@index_: the index of the first element to remove.
+@length: the number of elements to remove. 
+@Returns: the #GArray.
+@Since: 2.4
+
+
 <!-- ##### FUNCTION g_array_sort ##### -->
 <para>
-Sorts a #GArray using @compare_func which should be a <function>qsort()</function>-style comparison
+Sorts a #GArray using @compare_func which should be a qsort()-style comparison
 function (returns -1 for first arg is less than second arg, 0 for equal, 1 if
 first arg is greater than second arg).
 </para>
index f82d3ff866b109eeabeaa4dede63e88b51c0c499..92e0abc5360dc35416320f1d15aff736b05b4ad9 100644 (file)
@@ -125,9 +125,22 @@ g_byte_array_remove_index().
 @Returns: the #GByteArray.
 
 
+<!-- ##### FUNCTION g_byte_array_remove_range ##### -->
+<para>
+Removes the given number of bytes starting at the given index from a
+#GByteArray.  The following elements are moved to close the gap.
+</para>
+
+@array: a @GByteArray.
+@index_: the index of the first byte to remove.
+@length: the number of bytes to remove.
+@Returns: the #GByteArray.
+@Since: 2.4
+
+
 <!-- ##### FUNCTION g_byte_array_sort ##### -->
 <para>
-Sorts a byte array, using @compare_func which should be a <function>qsort()</function>-style
+Sorts a byte array, using @compare_func which should be a qsort()-style
 comparison function (returns -1 for first arg is less than second arg, 0 for
 equal, 1 if first arg is greater than second arg).
 </para>
index e609b44053e5702d5d2f64c2b1f6cf5920129b02..c67c253e40756e2e287438731fb5a487a6df8109 100644 (file)
@@ -155,9 +155,21 @@ g_ptr_array_remove_index().
 @Returns: the pointer which was removed.
 
 
+<!-- ##### FUNCTION g_ptr_array_remove_range ##### -->
+<para>
+Removes the given number of bytes starting at the given index from a
+#GPtrArray.  The following elements are moved to close the gap.
+</para>
+
+@array: a @GPtrArray.
+@index_: the index of the first pointer to remove.
+@length: the number of pointers to remove.
+@Since: 2.4
+
+
 <!-- ##### FUNCTION g_ptr_array_sort ##### -->
 <para>
-Sorts the array, using @compare_func which should be a <function>qsort()</function>-style comparison
+Sorts the array, using @compare_func which should be a qsort()-style comparison
 function (returns -1 for first arg is less than second arg, 0 for equal, 1 if
 first arg is greater than second arg).
 </para>
index 02e3d31c49814ad982bc7baffc56811492b99614..c7c6dacafc0ee7ae1fdeeefeffe5a80ad29301c3 100644 (file)
@@ -267,6 +267,32 @@ g_array_remove_index_fast (GArray* farray,
   return farray;
 }
 
+GArray*
+g_array_remove_range (GArray       *farray,
+                      guint         index_,
+                      guint         length)
+{
+  GRealArray *array = (GRealArray*) farray;
+
+  g_return_val_if_fail (array, NULL);
+  g_return_val_if_fail (index_ < array->len, NULL);
+  g_return_val_if_fail (index_ + length <= array->len, NULL);
+
+  if (index_ + length != array->len)
+    g_memmove (g_array_elt_pos (array, index_), 
+               g_array_elt_pos (array, index_ + length), 
+               (array->len - (index_ + length)) * array->elt_size);
+
+  array->len -= length;
+#ifdef ENABLE_GC_FRIENDLY
+  g_array_elt_zero (array, array->len, length);
+#else /* !ENABLE_GC_FRIENDLY */
+  g_array_zero_terminate (array);
+#endif /* ENABLE_GC_FRIENDLY */
+
+  return farray;
+}
+
 void
 g_array_sort (GArray       *farray,
              GCompareFunc  compare_func)
@@ -414,7 +440,7 @@ g_ptr_array_maybe_expand (GRealPtrArray *array,
 #endif /* ENABLE_GC_FRIENDLY */
       array->alloc = g_nearest_pow (array->len + len);
       array->alloc = MAX (array->alloc, MIN_ARRAY_SIZE);
-      array->pdata = g_realloc (array->pdata, sizeof(gpointer) * array->alloc);
+      array->pdata = g_realloc (array->pdata, sizeof (gpointer) * array->alloc);
 #ifdef ENABLE_GC_FRIENDLY
       for ( ; old_alloc < array->alloc; old_alloc++)
        array->pdata [old_alloc] = NULL;
@@ -506,6 +532,28 @@ g_ptr_array_remove_index_fast (GPtrArray* farray,
   return result;
 }
 
+void
+g_ptr_array_remove_range (GPtrArray* farray,
+                          guint      index_,
+                          guint      length)
+{
+  GRealPtrArray* array = (GRealPtrArray*) farray;
+
+  g_return_if_fail (array);
+  g_return_if_fail (index_ < array->len);
+  g_return_if_fail (index_ + length <= array->len);
+
+  if (index_ + length != array->len)
+    g_memmove (&array->pdata[index_],
+               &array->pdata[index_ + length], 
+               (array->len - (index_ + length)) * sizeof (gpointer));
+
+  array->len -= length;
+#ifdef ENABLE_GC_FRIENDLY
+  g_array_elt_zero (array->pdata, array->len, length);
+#endif /* ENABLE_GC_FRIENDLY */
+}
+
 gboolean
 g_ptr_array_remove (GPtrArray* farray,
                    gpointer data)
@@ -648,6 +696,18 @@ GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
   return array;
 }
 
+GByteArray*
+g_byte_array_remove_range (GByteArray *array,
+                           guint index_,
+                           guint length)
+{
+  g_return_val_if_fail (array, FALSE);
+  g_return_val_if_fail (index_ < array->len, FALSE);
+  g_return_val_if_fail (index_ + length <= array->len, FALSE);
+
+  return g_array_remove_range ((GArray*) array, index_, length);
+}
+
 void
 g_byte_array_sort (GByteArray   *array,
                   GCompareFunc  compare_func)
index c29d152602477fc461688905ff249cc309d3fafc..b35d99ae797abd03a99a53c8c942c0e826157c7b 100644 (file)
@@ -88,6 +88,9 @@ GArray* g_array_remove_index      (GArray           *array,
                                   guint             index_);
 GArray* g_array_remove_index_fast (GArray           *array,
                                   guint             index_);
+GArray* g_array_remove_range      (GArray           *array,
+                                  guint             index_,
+                                  guint             length);
 void    g_array_sort              (GArray           *array,
                                   GCompareFunc      compare_func);
 void    g_array_sort_with_data    (GArray           *array,
@@ -113,6 +116,9 @@ gboolean   g_ptr_array_remove             (GPtrArray        *array,
                                           gpointer          data);
 gboolean   g_ptr_array_remove_fast        (GPtrArray        *array,
                                           gpointer          data);
+void       g_ptr_array_remove_range       (GPtrArray        *array,
+                                          guint             index_,
+                                          guint             length);
 void       g_ptr_array_add                (GPtrArray        *array,
                                           gpointer          data);
 void       g_ptr_array_sort               (GPtrArray        *array,
@@ -142,6 +148,9 @@ GByteArray* g_byte_array_remove_index      (GByteArray       *array,
                                            guint             index_);
 GByteArray* g_byte_array_remove_index_fast (GByteArray       *array,
                                            guint             index_);
+GByteArray* g_byte_array_remove_range      (GByteArray       *array,
+                                           guint             index_,
+                                           guint             length);
 void        g_byte_array_sort              (GByteArray       *array,
                                            GCompareFunc      compare_func);
 void        g_byte_array_sort_with_data    (GByteArray       *array,