mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 10:16:17 +01:00
new function for removing an entry from an array while preserving the
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]
This commit is contained in:
parent
840114ac76
commit
4dbf739ea9
16
ChangeLog
16
ChangeLog
@ -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>
|
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib.h
|
* glib.h
|
||||||
|
@ -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>
|
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib.h
|
* glib.h
|
||||||
|
@ -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>
|
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib.h
|
* glib.h
|
||||||
|
@ -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>
|
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib.h
|
* glib.h
|
||||||
|
@ -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>
|
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib.h
|
* glib.h
|
||||||
|
@ -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>
|
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib.h
|
* glib.h
|
||||||
|
@ -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>
|
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib.h
|
* glib.h
|
||||||
|
@ -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>
|
Sun Nov 1 23:00:18 PST 1998 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib.h
|
* glib.h
|
||||||
|
114
garray.c
114
garray.c
@ -126,6 +126,54 @@ g_array_set_size (GArray *farray,
|
|||||||
return 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
|
static gint
|
||||||
g_nearest_pow (gint num)
|
g_nearest_pow (gint num)
|
||||||
{
|
{
|
||||||
@ -245,7 +293,7 @@ g_ptr_array_set_size (GPtrArray *farray,
|
|||||||
|
|
||||||
gpointer
|
gpointer
|
||||||
g_ptr_array_remove_index (GPtrArray* farray,
|
g_ptr_array_remove_index (GPtrArray* farray,
|
||||||
gint index)
|
guint index)
|
||||||
{
|
{
|
||||||
GRealPtrArray* array = (GRealPtrArray*) farray;
|
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||||
gpointer result;
|
gpointer result;
|
||||||
@ -255,8 +303,33 @@ g_ptr_array_remove_index (GPtrArray* farray,
|
|||||||
g_return_val_if_fail (index >= 0 && index < array->len, NULL);
|
g_return_val_if_fail (index >= 0 && index < array->len, NULL);
|
||||||
|
|
||||||
result = array->pdata[index];
|
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->pdata[index] = array->pdata[array->len - 1];
|
array->len -= 1;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpointer
|
||||||
|
g_ptr_array_remove_index_fast (GPtrArray* farray,
|
||||||
|
guint index)
|
||||||
|
{
|
||||||
|
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||||
|
gpointer result;
|
||||||
|
|
||||||
|
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;
|
array->pdata[array->len - 1] = NULL;
|
||||||
|
|
||||||
@ -286,6 +359,27 @@ g_ptr_array_remove (GPtrArray* farray,
|
|||||||
return FALSE;
|
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
|
void
|
||||||
g_ptr_array_add (GPtrArray* farray,
|
g_ptr_array_add (GPtrArray* farray,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
@ -338,3 +432,19 @@ GByteArray* g_byte_array_set_size (GByteArray *array,
|
|||||||
|
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
69
glib.h
69
glib.h
@ -1601,30 +1601,37 @@ void g_string_sprintfa (GString *string,
|
|||||||
...) G_GNUC_PRINTF (2, 3);
|
...) 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_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_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
|
||||||
#define g_array_index(a,t,i) (((t*)a->data)[i])
|
#define g_array_index(a,t,i) (((t*)a->data)[i])
|
||||||
|
|
||||||
GArray* g_array_new (gboolean zero_terminated,
|
GArray* g_array_new (gboolean zero_terminated,
|
||||||
gboolean clear,
|
gboolean clear,
|
||||||
guint element_size);
|
guint element_size);
|
||||||
void g_array_free (GArray *array,
|
void g_array_free (GArray *array,
|
||||||
gboolean free_segment);
|
gboolean free_segment);
|
||||||
GArray* g_array_append_vals (GArray *array,
|
GArray* g_array_append_vals (GArray *array,
|
||||||
gconstpointer data,
|
gconstpointer data,
|
||||||
guint len);
|
guint len);
|
||||||
GArray* g_array_prepend_vals (GArray *array,
|
GArray* g_array_prepend_vals (GArray *array,
|
||||||
gconstpointer data,
|
gconstpointer data,
|
||||||
guint len);
|
guint len);
|
||||||
GArray* g_array_set_size (GArray *array,
|
GArray* g_array_set_size (GArray *array,
|
||||||
guint length);
|
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
|
/* Resizable pointer array. This interface is much less complicated
|
||||||
* than the above. Add appends appends a pointer. Remove fills any
|
* 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]
|
#define g_ptr_array_index(array,index) (array->pdata)[index]
|
||||||
GPtrArray* g_ptr_array_new (void);
|
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,
|
void g_ptr_array_set_size (GPtrArray *array,
|
||||||
gint length);
|
gint length);
|
||||||
gpointer g_ptr_array_remove_index (GPtrArray *array,
|
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,
|
gboolean g_ptr_array_remove (GPtrArray *array,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
gboolean g_ptr_array_remove_fast (GPtrArray *array,
|
||||||
|
gpointer data);
|
||||||
void g_ptr_array_add (GPtrArray *array,
|
void g_ptr_array_add (GPtrArray *array,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
@ -1643,17 +1654,21 @@ void g_ptr_array_add (GPtrArray *array,
|
|||||||
* but type-safe.
|
* but type-safe.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GByteArray* g_byte_array_new (void);
|
GByteArray* g_byte_array_new (void);
|
||||||
void g_byte_array_free (GByteArray *array,
|
void g_byte_array_free (GByteArray *array,
|
||||||
gboolean free_segment);
|
gboolean free_segment);
|
||||||
GByteArray* g_byte_array_append (GByteArray *array,
|
GByteArray* g_byte_array_append (GByteArray *array,
|
||||||
const guint8 *data,
|
const guint8 *data,
|
||||||
guint len);
|
guint len);
|
||||||
GByteArray* g_byte_array_prepend (GByteArray *array,
|
GByteArray* g_byte_array_prepend (GByteArray *array,
|
||||||
const guint8 *data,
|
const guint8 *data,
|
||||||
guint len);
|
guint len);
|
||||||
GByteArray* g_byte_array_set_size (GByteArray *array,
|
GByteArray* g_byte_array_set_size (GByteArray *array,
|
||||||
guint length);
|
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
|
/* Hash Functions
|
||||||
|
114
glib/garray.c
114
glib/garray.c
@ -126,6 +126,54 @@ g_array_set_size (GArray *farray,
|
|||||||
return 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
|
static gint
|
||||||
g_nearest_pow (gint num)
|
g_nearest_pow (gint num)
|
||||||
{
|
{
|
||||||
@ -245,7 +293,7 @@ g_ptr_array_set_size (GPtrArray *farray,
|
|||||||
|
|
||||||
gpointer
|
gpointer
|
||||||
g_ptr_array_remove_index (GPtrArray* farray,
|
g_ptr_array_remove_index (GPtrArray* farray,
|
||||||
gint index)
|
guint index)
|
||||||
{
|
{
|
||||||
GRealPtrArray* array = (GRealPtrArray*) farray;
|
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||||
gpointer result;
|
gpointer result;
|
||||||
@ -255,8 +303,33 @@ g_ptr_array_remove_index (GPtrArray* farray,
|
|||||||
g_return_val_if_fail (index >= 0 && index < array->len, NULL);
|
g_return_val_if_fail (index >= 0 && index < array->len, NULL);
|
||||||
|
|
||||||
result = array->pdata[index];
|
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->pdata[index] = array->pdata[array->len - 1];
|
array->len -= 1;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpointer
|
||||||
|
g_ptr_array_remove_index_fast (GPtrArray* farray,
|
||||||
|
guint index)
|
||||||
|
{
|
||||||
|
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||||
|
gpointer result;
|
||||||
|
|
||||||
|
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;
|
array->pdata[array->len - 1] = NULL;
|
||||||
|
|
||||||
@ -286,6 +359,27 @@ g_ptr_array_remove (GPtrArray* farray,
|
|||||||
return FALSE;
|
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
|
void
|
||||||
g_ptr_array_add (GPtrArray* farray,
|
g_ptr_array_add (GPtrArray* farray,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
@ -338,3 +432,19 @@ GByteArray* g_byte_array_set_size (GByteArray *array,
|
|||||||
|
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
69
glib/glib.h
69
glib/glib.h
@ -1601,30 +1601,37 @@ void g_string_sprintfa (GString *string,
|
|||||||
...) G_GNUC_PRINTF (2, 3);
|
...) 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_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_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
|
||||||
#define g_array_index(a,t,i) (((t*)a->data)[i])
|
#define g_array_index(a,t,i) (((t*)a->data)[i])
|
||||||
|
|
||||||
GArray* g_array_new (gboolean zero_terminated,
|
GArray* g_array_new (gboolean zero_terminated,
|
||||||
gboolean clear,
|
gboolean clear,
|
||||||
guint element_size);
|
guint element_size);
|
||||||
void g_array_free (GArray *array,
|
void g_array_free (GArray *array,
|
||||||
gboolean free_segment);
|
gboolean free_segment);
|
||||||
GArray* g_array_append_vals (GArray *array,
|
GArray* g_array_append_vals (GArray *array,
|
||||||
gconstpointer data,
|
gconstpointer data,
|
||||||
guint len);
|
guint len);
|
||||||
GArray* g_array_prepend_vals (GArray *array,
|
GArray* g_array_prepend_vals (GArray *array,
|
||||||
gconstpointer data,
|
gconstpointer data,
|
||||||
guint len);
|
guint len);
|
||||||
GArray* g_array_set_size (GArray *array,
|
GArray* g_array_set_size (GArray *array,
|
||||||
guint length);
|
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
|
/* Resizable pointer array. This interface is much less complicated
|
||||||
* than the above. Add appends appends a pointer. Remove fills any
|
* 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]
|
#define g_ptr_array_index(array,index) (array->pdata)[index]
|
||||||
GPtrArray* g_ptr_array_new (void);
|
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,
|
void g_ptr_array_set_size (GPtrArray *array,
|
||||||
gint length);
|
gint length);
|
||||||
gpointer g_ptr_array_remove_index (GPtrArray *array,
|
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,
|
gboolean g_ptr_array_remove (GPtrArray *array,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
gboolean g_ptr_array_remove_fast (GPtrArray *array,
|
||||||
|
gpointer data);
|
||||||
void g_ptr_array_add (GPtrArray *array,
|
void g_ptr_array_add (GPtrArray *array,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
@ -1643,17 +1654,21 @@ void g_ptr_array_add (GPtrArray *array,
|
|||||||
* but type-safe.
|
* but type-safe.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GByteArray* g_byte_array_new (void);
|
GByteArray* g_byte_array_new (void);
|
||||||
void g_byte_array_free (GByteArray *array,
|
void g_byte_array_free (GByteArray *array,
|
||||||
gboolean free_segment);
|
gboolean free_segment);
|
||||||
GByteArray* g_byte_array_append (GByteArray *array,
|
GByteArray* g_byte_array_append (GByteArray *array,
|
||||||
const guint8 *data,
|
const guint8 *data,
|
||||||
guint len);
|
guint len);
|
||||||
GByteArray* g_byte_array_prepend (GByteArray *array,
|
GByteArray* g_byte_array_prepend (GByteArray *array,
|
||||||
const guint8 *data,
|
const guint8 *data,
|
||||||
guint len);
|
guint len);
|
||||||
GByteArray* g_byte_array_set_size (GByteArray *array,
|
GByteArray* g_byte_array_set_size (GByteArray *array,
|
||||||
guint length);
|
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
|
/* Hash Functions
|
||||||
|
Loading…
Reference in New Issue
Block a user