diff options
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | ChangeLog.pre-2-0 | 16 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 16 | ||||
-rw-r--r-- | ChangeLog.pre-2-12 | 16 | ||||
-rw-r--r-- | ChangeLog.pre-2-2 | 16 | ||||
-rw-r--r-- | ChangeLog.pre-2-4 | 16 | ||||
-rw-r--r-- | ChangeLog.pre-2-6 | 16 | ||||
-rw-r--r-- | ChangeLog.pre-2-8 | 16 | ||||
-rw-r--r-- | garray.c | 114 | ||||
-rw-r--r-- | glib.h | 69 | ||||
-rw-r--r-- | glib/garray.c | 114 | ||||
-rw-r--r-- | glib/glib.h | 69 |
12 files changed, 436 insertions, 58 deletions
@@ -1,3 +1,19 @@ +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 diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 1f3c7fff0..62c715bb0 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,19 @@ +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 diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 1f3c7fff0..62c715bb0 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,19 @@ +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 diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 1f3c7fff0..62c715bb0 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,19 @@ +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 diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 1f3c7fff0..62c715bb0 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,19 @@ +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 diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 1f3c7fff0..62c715bb0 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,19 @@ +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 diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 1f3c7fff0..62c715bb0 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,19 @@ +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 diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 1f3c7fff0..62c715bb0 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,19 @@ +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 @@ -126,6 +126,54 @@ g_array_set_size (GArray *farray, 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) { @@ -245,7 +293,7 @@ g_ptr_array_set_size (GPtrArray *farray, gpointer g_ptr_array_remove_index (GPtrArray* farray, - gint index) + guint index) { GRealPtrArray* array = (GRealPtrArray*) farray; gpointer result; @@ -255,8 +303,33 @@ g_ptr_array_remove_index (GPtrArray* farray, 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; @@ -286,6 +359,27 @@ g_ptr_array_remove (GPtrArray* farray, 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) @@ -338,3 +432,19 @@ GByteArray* g_byte_array_set_size (GByteArray *array, 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; +} @@ -1601,30 +1601,37 @@ void g_string_sprintfa (GString *string, ...) 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); @@ -1633,9 +1640,13 @@ void g_ptr_array_free (GPtrArray *array, 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); @@ -1643,17 +1654,21 @@ void g_ptr_array_add (GPtrArray *array, * 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 diff --git a/glib/garray.c b/glib/garray.c index 4425f1d29..fd5e7b9e2 100644 --- a/glib/garray.c +++ b/glib/garray.c @@ -126,6 +126,54 @@ g_array_set_size (GArray *farray, 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) { @@ -245,7 +293,7 @@ g_ptr_array_set_size (GPtrArray *farray, gpointer g_ptr_array_remove_index (GPtrArray* farray, - gint index) + guint index) { GRealPtrArray* array = (GRealPtrArray*) farray; gpointer result; @@ -255,8 +303,33 @@ g_ptr_array_remove_index (GPtrArray* farray, 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; @@ -286,6 +359,27 @@ g_ptr_array_remove (GPtrArray* farray, 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) @@ -338,3 +432,19 @@ GByteArray* g_byte_array_set_size (GByteArray *array, 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; +} diff --git a/glib/glib.h b/glib/glib.h index c98dc7873..72941f7a9 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -1601,30 +1601,37 @@ void g_string_sprintfa (GString *string, ...) 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); @@ -1633,9 +1640,13 @@ void g_ptr_array_free (GPtrArray *array, 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); @@ -1643,17 +1654,21 @@ void g_ptr_array_add (GPtrArray *array, * 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 |