+1998-11-03 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * glib.h:
+ * garray.h:
+ (g_array_remove_index): new function for removing an entry from an
+ array while preserving the order
+ (g_array_remove_index_fast): new function for removing an entry
+ from an array. the order might be distorted
+ (g_ptr_array_remove_index_fast, g_ptr_array_remove_fast): new
+ functions; working similiar to the above. (they have the semantic
+ of the old g_ptr_array_remove[_index] functions)
+ (g_ptr_array_remove_index, g_ptr_array_remove): new semantic. now
+ the order of the elements in the array is not changed
+ (g_byte_array_remove_index, g_byte_array_remove_index_fast): new
+ functions; byte_array wrapper for g_array_remove_index[_fast]
+
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
* glib.h
+1998-11-03 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * glib.h:
+ * garray.h:
+ (g_array_remove_index): new function for removing an entry from an
+ array while preserving the order
+ (g_array_remove_index_fast): new function for removing an entry
+ from an array. the order might be distorted
+ (g_ptr_array_remove_index_fast, g_ptr_array_remove_fast): new
+ functions; working similiar to the above. (they have the semantic
+ of the old g_ptr_array_remove[_index] functions)
+ (g_ptr_array_remove_index, g_ptr_array_remove): new semantic. now
+ the order of the elements in the array is not changed
+ (g_byte_array_remove_index, g_byte_array_remove_index_fast): new
+ functions; byte_array wrapper for g_array_remove_index[_fast]
+
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
* glib.h
+1998-11-03 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * glib.h:
+ * garray.h:
+ (g_array_remove_index): new function for removing an entry from an
+ array while preserving the order
+ (g_array_remove_index_fast): new function for removing an entry
+ from an array. the order might be distorted
+ (g_ptr_array_remove_index_fast, g_ptr_array_remove_fast): new
+ functions; working similiar to the above. (they have the semantic
+ of the old g_ptr_array_remove[_index] functions)
+ (g_ptr_array_remove_index, g_ptr_array_remove): new semantic. now
+ the order of the elements in the array is not changed
+ (g_byte_array_remove_index, g_byte_array_remove_index_fast): new
+ functions; byte_array wrapper for g_array_remove_index[_fast]
+
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
* glib.h
+1998-11-03 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * glib.h:
+ * garray.h:
+ (g_array_remove_index): new function for removing an entry from an
+ array while preserving the order
+ (g_array_remove_index_fast): new function for removing an entry
+ from an array. the order might be distorted
+ (g_ptr_array_remove_index_fast, g_ptr_array_remove_fast): new
+ functions; working similiar to the above. (they have the semantic
+ of the old g_ptr_array_remove[_index] functions)
+ (g_ptr_array_remove_index, g_ptr_array_remove): new semantic. now
+ the order of the elements in the array is not changed
+ (g_byte_array_remove_index, g_byte_array_remove_index_fast): new
+ functions; byte_array wrapper for g_array_remove_index[_fast]
+
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
* glib.h
+1998-11-03 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * glib.h:
+ * garray.h:
+ (g_array_remove_index): new function for removing an entry from an
+ array while preserving the order
+ (g_array_remove_index_fast): new function for removing an entry
+ from an array. the order might be distorted
+ (g_ptr_array_remove_index_fast, g_ptr_array_remove_fast): new
+ functions; working similiar to the above. (they have the semantic
+ of the old g_ptr_array_remove[_index] functions)
+ (g_ptr_array_remove_index, g_ptr_array_remove): new semantic. now
+ the order of the elements in the array is not changed
+ (g_byte_array_remove_index, g_byte_array_remove_index_fast): new
+ functions; byte_array wrapper for g_array_remove_index[_fast]
+
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
* glib.h
+1998-11-03 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * glib.h:
+ * garray.h:
+ (g_array_remove_index): new function for removing an entry from an
+ array while preserving the order
+ (g_array_remove_index_fast): new function for removing an entry
+ from an array. the order might be distorted
+ (g_ptr_array_remove_index_fast, g_ptr_array_remove_fast): new
+ functions; working similiar to the above. (they have the semantic
+ of the old g_ptr_array_remove[_index] functions)
+ (g_ptr_array_remove_index, g_ptr_array_remove): new semantic. now
+ the order of the elements in the array is not changed
+ (g_byte_array_remove_index, g_byte_array_remove_index_fast): new
+ functions; byte_array wrapper for g_array_remove_index[_fast]
+
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
* glib.h
+1998-11-03 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * glib.h:
+ * garray.h:
+ (g_array_remove_index): new function for removing an entry from an
+ array while preserving the order
+ (g_array_remove_index_fast): new function for removing an entry
+ from an array. the order might be distorted
+ (g_ptr_array_remove_index_fast, g_ptr_array_remove_fast): new
+ functions; working similiar to the above. (they have the semantic
+ of the old g_ptr_array_remove[_index] functions)
+ (g_ptr_array_remove_index, g_ptr_array_remove): new semantic. now
+ the order of the elements in the array is not changed
+ (g_byte_array_remove_index, g_byte_array_remove_index_fast): new
+ functions; byte_array wrapper for g_array_remove_index[_fast]
+
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
* glib.h
+1998-11-03 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * glib.h:
+ * garray.h:
+ (g_array_remove_index): new function for removing an entry from an
+ array while preserving the order
+ (g_array_remove_index_fast): new function for removing an entry
+ from an array. the order might be distorted
+ (g_ptr_array_remove_index_fast, g_ptr_array_remove_fast): new
+ functions; working similiar to the above. (they have the semantic
+ of the old g_ptr_array_remove[_index] functions)
+ (g_ptr_array_remove_index, g_ptr_array_remove): new semantic. now
+ the order of the elements in the array is not changed
+ (g_byte_array_remove_index, g_byte_array_remove_index_fast): new
+ functions; byte_array wrapper for g_array_remove_index[_fast]
+
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
* glib.h
return farray;
}
+GArray*
+g_array_remove_index (GArray* farray,
+ guint index)
+{
+ GRealArray* array = (GRealArray*) farray;
+
+ g_return_val_if_fail (array, NULL);
+
+ g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+
+ if (index != array->len - 1)
+ g_memmove (array->data + array->elt_size * index,
+ array->data + array->elt_size * (index + 1),
+ array->elt_size * (array->len - index - 1));
+
+ if (array->zero_terminated)
+ memset (array->data + array->elt_size * (array->len - 1), 0,
+ array->elt_size);
+
+ array->len -= 1;
+
+ return farray;
+}
+
+GArray*
+g_array_remove_index_fast (GArray* farray,
+ guint index)
+{
+ GRealArray* array = (GRealArray*) farray;
+
+ g_return_val_if_fail (array, NULL);
+
+ g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+
+ if (index != array->len - 1)
+ g_memmove (array->data + array->elt_size * index,
+ array->data + array->elt_size * (array->len - 1),
+ array->elt_size);
+
+ if (array->zero_terminated)
+ memset (array->data + array->elt_size * (array->len - 1), 0,
+ array->elt_size);
+
+ array->len -= 1;
+
+ return farray;
+}
+
static gint
g_nearest_pow (gint num)
{
gpointer
g_ptr_array_remove_index (GPtrArray* farray,
- gint index)
+ guint index)
{
GRealPtrArray* array = (GRealPtrArray*) farray;
gpointer result;
g_return_val_if_fail (index >= 0 && index < array->len, NULL);
result = array->pdata[index];
+
+ if (index != array->len - 1)
+ g_memmove (array->pdata + index, array->pdata + index + 1,
+ array->len - index - 1);
+
+ array->pdata[array->len - 1] = NULL;
+
+ array->len -= 1;
+
+ return result;
+}
+
+gpointer
+g_ptr_array_remove_index_fast (GPtrArray* farray,
+ guint index)
+{
+ GRealPtrArray* array = (GRealPtrArray*) farray;
+ gpointer result;
- array->pdata[index] = array->pdata[array->len - 1];
+ g_return_val_if_fail (array, NULL);
+
+ g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+
+ result = array->pdata[index];
+
+ if (index != array->len - 1)
+ array->pdata[index] = array->pdata[array->len - 1];
array->pdata[array->len - 1] = NULL;
return FALSE;
}
+gboolean
+g_ptr_array_remove_fast (GPtrArray* farray,
+ gpointer data)
+{
+ GRealPtrArray* array = (GRealPtrArray*) farray;
+ int i;
+
+ g_return_val_if_fail (array, FALSE);
+
+ for (i = 0; i < array->len; i += 1)
+ {
+ if (array->pdata[i] == data)
+ {
+ g_ptr_array_remove_index_fast (farray, i);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
void
g_ptr_array_add (GPtrArray* farray,
gpointer data)
return array;
}
+
+GByteArray* g_byte_array_remove_index (GByteArray *array,
+ guint index)
+{
+ g_array_remove_index((GArray*) array, index);
+
+ return array;
+}
+
+GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
+ guint index)
+{
+ g_array_remove_index_fast((GArray*) array, index);
+
+ return array;
+}
...) G_GNUC_PRINTF (2, 3);
-/* Resizable arrays
+/* Resizable arrays, remove fills any cleared spot and shortens the
+ * array, while preserving the order. remove_fast will distort the
+ * order by moving the last element to the position of the removed
*/
#define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
#define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
#define g_array_index(a,t,i) (((t*)a->data)[i])
-GArray* g_array_new (gboolean zero_terminated,
- gboolean clear,
- guint element_size);
-void g_array_free (GArray *array,
- gboolean free_segment);
-GArray* g_array_append_vals (GArray *array,
- gconstpointer data,
- guint len);
-GArray* g_array_prepend_vals (GArray *array,
- gconstpointer data,
- guint len);
-GArray* g_array_set_size (GArray *array,
- guint length);
+GArray* g_array_new (gboolean zero_terminated,
+ gboolean clear,
+ guint element_size);
+void g_array_free (GArray *array,
+ gboolean free_segment);
+GArray* g_array_append_vals (GArray *array,
+ gconstpointer data,
+ guint len);
+GArray* g_array_prepend_vals (GArray *array,
+ gconstpointer data,
+ guint len);
+GArray* g_array_set_size (GArray *array,
+ guint length);
+GArray* g_array_remove_index (GArray *array,
+ guint index);
+GArray* g_array_remove_index_fast (GArray *array,
+ guint index);
/* Resizable pointer array. This interface is much less complicated
* than the above. Add appends appends a pointer. Remove fills any
- * cleared spot and shortens the array.
+ * cleared spot and shortens the array. remove_fast will again distort
+ * order.
*/
#define g_ptr_array_index(array,index) (array->pdata)[index]
GPtrArray* g_ptr_array_new (void);
void g_ptr_array_set_size (GPtrArray *array,
gint length);
gpointer g_ptr_array_remove_index (GPtrArray *array,
- gint index);
+ guint index);
+gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
+ guint index);
gboolean g_ptr_array_remove (GPtrArray *array,
gpointer data);
+gboolean g_ptr_array_remove_fast (GPtrArray *array,
+ gpointer data);
void g_ptr_array_add (GPtrArray *array,
gpointer data);
* but type-safe.
*/
-GByteArray* g_byte_array_new (void);
-void g_byte_array_free (GByteArray *array,
- gboolean free_segment);
-GByteArray* g_byte_array_append (GByteArray *array,
- const guint8 *data,
- guint len);
-GByteArray* g_byte_array_prepend (GByteArray *array,
- const guint8 *data,
- guint len);
-GByteArray* g_byte_array_set_size (GByteArray *array,
- guint length);
+GByteArray* g_byte_array_new (void);
+void g_byte_array_free (GByteArray *array,
+ gboolean free_segment);
+GByteArray* g_byte_array_append (GByteArray *array,
+ const guint8 *data,
+ guint len);
+GByteArray* g_byte_array_prepend (GByteArray *array,
+ const guint8 *data,
+ guint len);
+GByteArray* g_byte_array_set_size (GByteArray *array,
+ guint length);
+GByteArray* g_byte_array_remove_index (GByteArray *array,
+ guint index);
+GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
+ guint index);
/* Hash Functions
return farray;
}
+GArray*
+g_array_remove_index (GArray* farray,
+ guint index)
+{
+ GRealArray* array = (GRealArray*) farray;
+
+ g_return_val_if_fail (array, NULL);
+
+ g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+
+ if (index != array->len - 1)
+ g_memmove (array->data + array->elt_size * index,
+ array->data + array->elt_size * (index + 1),
+ array->elt_size * (array->len - index - 1));
+
+ if (array->zero_terminated)
+ memset (array->data + array->elt_size * (array->len - 1), 0,
+ array->elt_size);
+
+ array->len -= 1;
+
+ return farray;
+}
+
+GArray*
+g_array_remove_index_fast (GArray* farray,
+ guint index)
+{
+ GRealArray* array = (GRealArray*) farray;
+
+ g_return_val_if_fail (array, NULL);
+
+ g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+
+ if (index != array->len - 1)
+ g_memmove (array->data + array->elt_size * index,
+ array->data + array->elt_size * (array->len - 1),
+ array->elt_size);
+
+ if (array->zero_terminated)
+ memset (array->data + array->elt_size * (array->len - 1), 0,
+ array->elt_size);
+
+ array->len -= 1;
+
+ return farray;
+}
+
static gint
g_nearest_pow (gint num)
{
gpointer
g_ptr_array_remove_index (GPtrArray* farray,
- gint index)
+ guint index)
{
GRealPtrArray* array = (GRealPtrArray*) farray;
gpointer result;
g_return_val_if_fail (index >= 0 && index < array->len, NULL);
result = array->pdata[index];
+
+ if (index != array->len - 1)
+ g_memmove (array->pdata + index, array->pdata + index + 1,
+ array->len - index - 1);
+
+ array->pdata[array->len - 1] = NULL;
+
+ array->len -= 1;
+
+ return result;
+}
+
+gpointer
+g_ptr_array_remove_index_fast (GPtrArray* farray,
+ guint index)
+{
+ GRealPtrArray* array = (GRealPtrArray*) farray;
+ gpointer result;
- array->pdata[index] = array->pdata[array->len - 1];
+ g_return_val_if_fail (array, NULL);
+
+ g_return_val_if_fail (index >= 0 && index < array->len, NULL);
+
+ result = array->pdata[index];
+
+ if (index != array->len - 1)
+ array->pdata[index] = array->pdata[array->len - 1];
array->pdata[array->len - 1] = NULL;
return FALSE;
}
+gboolean
+g_ptr_array_remove_fast (GPtrArray* farray,
+ gpointer data)
+{
+ GRealPtrArray* array = (GRealPtrArray*) farray;
+ int i;
+
+ g_return_val_if_fail (array, FALSE);
+
+ for (i = 0; i < array->len; i += 1)
+ {
+ if (array->pdata[i] == data)
+ {
+ g_ptr_array_remove_index_fast (farray, i);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
void
g_ptr_array_add (GPtrArray* farray,
gpointer data)
return array;
}
+
+GByteArray* g_byte_array_remove_index (GByteArray *array,
+ guint index)
+{
+ g_array_remove_index((GArray*) array, index);
+
+ return array;
+}
+
+GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
+ guint index)
+{
+ g_array_remove_index_fast((GArray*) array, index);
+
+ return array;
+}
...) G_GNUC_PRINTF (2, 3);
-/* Resizable arrays
+/* Resizable arrays, remove fills any cleared spot and shortens the
+ * array, while preserving the order. remove_fast will distort the
+ * order by moving the last element to the position of the removed
*/
#define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
#define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
#define g_array_index(a,t,i) (((t*)a->data)[i])
-GArray* g_array_new (gboolean zero_terminated,
- gboolean clear,
- guint element_size);
-void g_array_free (GArray *array,
- gboolean free_segment);
-GArray* g_array_append_vals (GArray *array,
- gconstpointer data,
- guint len);
-GArray* g_array_prepend_vals (GArray *array,
- gconstpointer data,
- guint len);
-GArray* g_array_set_size (GArray *array,
- guint length);
+GArray* g_array_new (gboolean zero_terminated,
+ gboolean clear,
+ guint element_size);
+void g_array_free (GArray *array,
+ gboolean free_segment);
+GArray* g_array_append_vals (GArray *array,
+ gconstpointer data,
+ guint len);
+GArray* g_array_prepend_vals (GArray *array,
+ gconstpointer data,
+ guint len);
+GArray* g_array_set_size (GArray *array,
+ guint length);
+GArray* g_array_remove_index (GArray *array,
+ guint index);
+GArray* g_array_remove_index_fast (GArray *array,
+ guint index);
/* Resizable pointer array. This interface is much less complicated
* than the above. Add appends appends a pointer. Remove fills any
- * cleared spot and shortens the array.
+ * cleared spot and shortens the array. remove_fast will again distort
+ * order.
*/
#define g_ptr_array_index(array,index) (array->pdata)[index]
GPtrArray* g_ptr_array_new (void);
void g_ptr_array_set_size (GPtrArray *array,
gint length);
gpointer g_ptr_array_remove_index (GPtrArray *array,
- gint index);
+ guint index);
+gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
+ guint index);
gboolean g_ptr_array_remove (GPtrArray *array,
gpointer data);
+gboolean g_ptr_array_remove_fast (GPtrArray *array,
+ gpointer data);
void g_ptr_array_add (GPtrArray *array,
gpointer data);
* but type-safe.
*/
-GByteArray* g_byte_array_new (void);
-void g_byte_array_free (GByteArray *array,
- gboolean free_segment);
-GByteArray* g_byte_array_append (GByteArray *array,
- const guint8 *data,
- guint len);
-GByteArray* g_byte_array_prepend (GByteArray *array,
- const guint8 *data,
- guint len);
-GByteArray* g_byte_array_set_size (GByteArray *array,
- guint length);
+GByteArray* g_byte_array_new (void);
+void g_byte_array_free (GByteArray *array,
+ gboolean free_segment);
+GByteArray* g_byte_array_append (GByteArray *array,
+ const guint8 *data,
+ guint len);
+GByteArray* g_byte_array_prepend (GByteArray *array,
+ const guint8 *data,
+ guint len);
+GByteArray* g_byte_array_set_size (GByteArray *array,
+ guint length);
+GByteArray* g_byte_array_remove_index (GByteArray *array,
+ guint index);
+GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
+ guint index);
/* Hash Functions