Commit 2645aaf5 authored by Jonathan Blandford's avatar Jonathan Blandford Committed by Jonathan Blandford

Patch from David Benson <daveb@idealab.com> to add user_data support to

Mon Nov 20 18:55:17 2000  Jonathan Blandford  <jrb@redhat.com>

	* gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add
	user_data support to gtree functions.

Mon Nov 13 18:35:52 2000  Jonathan Blandford  <jrb@redhat.com>

	* gtypes.h (GCompareFuncData): new func type to let you use user
	data when comparing nodes.

	* gslist.c (g_list_sort_with_data): new function to sort with
	user_data.

	* glist.c (g_list_sort_with_data): new function to sort with
	user_data.

	* garray.[ch]: Added convenience functions to sort arrays.
parent 40d62d0d
Mon Nov 20 18:55:17 2000 Jonathan Blandford <jrb@redhat.com>
* gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add
user_data support to gtree functions.
Mon Nov 13 18:35:52 2000 Jonathan Blandford <jrb@redhat.com>
* gtypes.h (GCompareFuncData): new func type to let you use user
data when comparing nodes.
* gslist.c (g_list_sort_with_data): new function to sort with
user_data.
* glist.c (g_list_sort_with_data): new function to sort with
user_data.
* garray.[ch]: Added convenience functions to sort arrays.
2000-11-16 Havoc Pennington <hp@redhat.com>
* guniprop.c (g_unichar_isspace): Use a switch here, maybe helps
......
Mon Nov 20 18:55:17 2000 Jonathan Blandford <jrb@redhat.com>
* gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add
user_data support to gtree functions.
Mon Nov 13 18:35:52 2000 Jonathan Blandford <jrb@redhat.com>
* gtypes.h (GCompareFuncData): new func type to let you use user
data when comparing nodes.
* gslist.c (g_list_sort_with_data): new function to sort with
user_data.
* glist.c (g_list_sort_with_data): new function to sort with
user_data.
* garray.[ch]: Added convenience functions to sort arrays.
2000-11-16 Havoc Pennington <hp@redhat.com>
* guniprop.c (g_unichar_isspace): Use a switch here, maybe helps
......
Mon Nov 20 18:55:17 2000 Jonathan Blandford <jrb@redhat.com>
* gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add
user_data support to gtree functions.
Mon Nov 13 18:35:52 2000 Jonathan Blandford <jrb@redhat.com>
* gtypes.h (GCompareFuncData): new func type to let you use user
data when comparing nodes.
* gslist.c (g_list_sort_with_data): new function to sort with
user_data.
* glist.c (g_list_sort_with_data): new function to sort with
user_data.
* garray.[ch]: Added convenience functions to sort arrays.
2000-11-16 Havoc Pennington <hp@redhat.com>
* guniprop.c (g_unichar_isspace): Use a switch here, maybe helps
......
Mon Nov 20 18:55:17 2000 Jonathan Blandford <jrb@redhat.com>
* gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add
user_data support to gtree functions.
Mon Nov 13 18:35:52 2000 Jonathan Blandford <jrb@redhat.com>
* gtypes.h (GCompareFuncData): new func type to let you use user
data when comparing nodes.
* gslist.c (g_list_sort_with_data): new function to sort with
user_data.
* glist.c (g_list_sort_with_data): new function to sort with
user_data.
* garray.[ch]: Added convenience functions to sort arrays.
2000-11-16 Havoc Pennington <hp@redhat.com>
* guniprop.c (g_unichar_isspace): Use a switch here, maybe helps
......
Mon Nov 20 18:55:17 2000 Jonathan Blandford <jrb@redhat.com>
* gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add
user_data support to gtree functions.
Mon Nov 13 18:35:52 2000 Jonathan Blandford <jrb@redhat.com>
* gtypes.h (GCompareFuncData): new func type to let you use user
data when comparing nodes.
* gslist.c (g_list_sort_with_data): new function to sort with
user_data.
* glist.c (g_list_sort_with_data): new function to sort with
user_data.
* garray.[ch]: Added convenience functions to sort arrays.
2000-11-16 Havoc Pennington <hp@redhat.com>
* guniprop.c (g_unichar_isspace): Use a switch here, maybe helps
......
Mon Nov 20 18:55:17 2000 Jonathan Blandford <jrb@redhat.com>
* gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add
user_data support to gtree functions.
Mon Nov 13 18:35:52 2000 Jonathan Blandford <jrb@redhat.com>
* gtypes.h (GCompareFuncData): new func type to let you use user
data when comparing nodes.
* gslist.c (g_list_sort_with_data): new function to sort with
user_data.
* glist.c (g_list_sort_with_data): new function to sort with
user_data.
* garray.[ch]: Added convenience functions to sort arrays.
2000-11-16 Havoc Pennington <hp@redhat.com>
* guniprop.c (g_unichar_isspace): Use a switch here, maybe helps
......
Mon Nov 20 18:55:17 2000 Jonathan Blandford <jrb@redhat.com>
* gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add
user_data support to gtree functions.
Mon Nov 13 18:35:52 2000 Jonathan Blandford <jrb@redhat.com>
* gtypes.h (GCompareFuncData): new func type to let you use user
data when comparing nodes.
* gslist.c (g_list_sort_with_data): new function to sort with
user_data.
* glist.c (g_list_sort_with_data): new function to sort with
user_data.
* garray.[ch]: Added convenience functions to sort arrays.
2000-11-16 Havoc Pennington <hp@redhat.com>
* guniprop.c (g_unichar_isspace): Use a switch here, maybe helps
......
Mon Nov 20 18:55:17 2000 Jonathan Blandford <jrb@redhat.com>
* gtree.[hc]: Patch from David Benson <daveb@idealab.com> to add
user_data support to gtree functions.
Mon Nov 13 18:35:52 2000 Jonathan Blandford <jrb@redhat.com>
* gtypes.h (GCompareFuncData): new func type to let you use user
data when comparing nodes.
* gslist.c (g_list_sort_with_data): new function to sort with
user_data.
* glist.c (g_list_sort_with_data): new function to sort with
user_data.
* garray.[ch]: Added convenience functions to sort arrays.
2000-11-16 Havoc Pennington <hp@redhat.com>
* guniprop.c (g_unichar_isspace): Use a switch here, maybe helps
......
......@@ -66,6 +66,7 @@ libglib_1_3_la_SOURCES = \
gmessages.c \
gnode.c \
gprimes.c \
gqsort.c \
gqueue.c \
grel.c \
grand.c \
......@@ -115,6 +116,7 @@ glibinclude_HEADERS = \
gmessages.h \
gnode.h \
gprimes.h \
gqsort.h \
gquark.h \
gqueue.h \
grand.h \
......
......@@ -29,6 +29,7 @@
*/
#include <string.h>
#include <stdlib.h>
#include "glib.h"
......@@ -264,6 +265,39 @@ g_array_remove_index_fast (GArray* farray,
return farray;
}
void
g_array_sort (GArray *farray,
GCompareFunc compare_func)
{
GRealArray *array = (GRealArray*) farray;
g_return_if_fail (array != NULL);
g_return_if_fail (array->data != NULL);
qsort (array->data,
array->len,
array->elt_size,
compare_func);
}
void
g_array_sort_with_data (GArray *farray,
GCompareFuncData compare_func,
gpointer user_data)
{
GRealArray *array = (GRealArray*) farray;
g_return_if_fail (array != NULL);
g_return_if_fail (array->data != NULL);
g_qsort_with_data (array->data,
array->len,
array->elt_size,
compare_func,
user_data);
}
static gint
g_nearest_pow (gint num)
{
......@@ -527,6 +561,34 @@ g_ptr_array_add (GPtrArray* farray,
array->pdata[array->len++] = data;
}
void
g_ptr_array_sort (GPtrArray *array,
GCompareFunc compare_func)
{
g_return_if_fail (array != NULL);
g_return_if_fail (array->pdata != NULL);
qsort (array->pdata,
array->len,
sizeof (gpointer),
compare_func);
}
void
g_ptr_array_sort_with_data (GPtrArray *array,
GCompareFuncData compare_func,
gpointer user_data)
{
g_return_if_fail (array != NULL);
g_return_if_fail (array->pdata != NULL);
g_qsort_with_data (array->pdata,
array->len,
sizeof (gpointer),
compare_func,
user_data);
}
/* Byte arrays
*/
......@@ -581,9 +643,24 @@ GByteArray* g_byte_array_remove_index (GByteArray *array,
}
GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
guint index)
guint index)
{
g_array_remove_index_fast((GArray*) array, index);
return array;
}
void
g_byte_array_sort (GByteArray *array,
GCompareFunc compare_func)
{
g_array_sort ((GArray *) array, compare_func);
}
void
g_byte_array_sort_with_data (GByteArray *array,
GCompareFuncData compare_func,
gpointer user_data)
{
g_array_sort_with_data ((GArray *) array, compare_func, user_data);
}
......@@ -63,75 +63,92 @@ struct _GPtrArray
#define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &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);
GArray* g_array_sized_new (gboolean zero_terminated,
gboolean clear,
guint element_size,
guint reserved_size);
gchar* 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_insert_vals (GArray *array,
guint index,
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);
GArray* g_array_new (gboolean zero_terminated,
gboolean clear,
guint element_size);
GArray* g_array_sized_new (gboolean zero_terminated,
gboolean clear,
guint element_size,
guint reserved_size);
gchar* 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_insert_vals (GArray *array,
guint index,
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);
void g_array_sort (GArray *array,
GCompareFunc compare_func);
void g_array_sort_with_data (GArray *array,
GCompareFuncData compare_func,
gpointer user_data);
/* 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. remove_fast will again distort
* order.
*/
#define g_ptr_array_index(array,index) (array->pdata)[index]
GPtrArray* g_ptr_array_new (void);
GPtrArray* g_ptr_array_sized_new (guint reserved_size);
gpointer* g_ptr_array_free (GPtrArray *array,
gboolean free_seg);
void g_ptr_array_set_size (GPtrArray *array,
gint length);
gpointer g_ptr_array_remove_index (GPtrArray *array,
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);
#define g_ptr_array_index(array,index) (array->pdata)[index]
GPtrArray* g_ptr_array_new (void);
GPtrArray* g_ptr_array_sized_new (guint reserved_size);
gpointer* g_ptr_array_free (GPtrArray *array,
gboolean free_seg);
void g_ptr_array_set_size (GPtrArray *array,
gint length);
gpointer g_ptr_array_remove_index (GPtrArray *array,
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);
void g_ptr_array_sort (GPtrArray *array,
GCompareFunc compare_func);
void g_ptr_array_sort_with_data (GPtrArray *array,
GCompareFuncData compare_func,
gpointer user_data);
/* Byte arrays, an array of guint8. Implemented as a GArray,
* but type-safe.
*/
GByteArray* g_byte_array_new (void);
GByteArray* g_byte_array_sized_new (guint reserved_size);
guint8* 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);
GByteArray* g_byte_array_new (void);
GByteArray* g_byte_array_sized_new (guint reserved_size);
guint8* 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);
void g_byte_array_sort (GByteArray *array,
GCompareFunc compare_func);
void g_byte_array_sort_with_data (GByteArray *array,
GCompareFuncData compare_func,
gpointer user_data);
G_END_DECLS
......
......@@ -49,6 +49,7 @@
#include <gmessages.h>
#include <gnode.h>
#include <gprimes.h>
#include <gqsort.h>
#include <gquark.h>
#include <gqueue.h>
#include <grand.h>
......
......@@ -66,6 +66,7 @@ libglib_1_3_la_SOURCES = \
gmessages.c \
gnode.c \
gprimes.c \
gqsort.c \
gqueue.c \
grel.c \
grand.c \
......@@ -115,6 +116,7 @@ glibinclude_HEADERS = \
gmessages.h \
gnode.h \
gprimes.h \
gqsort.h \
gquark.h \
gqueue.h \
grand.h \
......
......@@ -29,6 +29,7 @@
*/
#include <string.h>
#include <stdlib.h>
#include "glib.h"
......@@ -264,6 +265,39 @@ g_array_remove_index_fast (GArray* farray,
return farray;
}
void
g_array_sort (GArray *farray,
GCompareFunc compare_func)
{
GRealArray *array = (GRealArray*) farray;
g_return_if_fail (array != NULL);
g_return_if_fail (array->data != NULL);
qsort (array->data,
array->len,
array->elt_size,
compare_func);
}
void
g_array_sort_with_data (GArray *farray,
GCompareFuncData compare_func,
gpointer user_data)
{
GRealArray *array = (GRealArray*) farray;
g_return_if_fail (array != NULL);
g_return_if_fail (array->data != NULL);
g_qsort_with_data (array->data,
array->len,
array->elt_size,
compare_func,
user_data);
}
static gint
g_nearest_pow (gint num)
{
......@@ -527,6 +561,34 @@ g_ptr_array_add (GPtrArray* farray,
array->pdata[array->len++] = data;
}
void
g_ptr_array_sort (GPtrArray *array,
GCompareFunc compare_func)
{
g_return_if_fail (array != NULL);
g_return_if_fail (array->pdata != NULL);
qsort (array->pdata,
array->len,
sizeof (gpointer),
compare_func);
}
void
g_ptr_array_sort_with_data (GPtrArray *array,
GCompareFuncData compare_func,
gpointer user_data)
{
g_return_if_fail (array != NULL);
g_return_if_fail (array->pdata != NULL);
g_qsort_with_data (array->pdata,
array->len,
sizeof (gpointer),
compare_func,
user_data);
}
/* Byte arrays
*/
......@@ -581,9 +643,24 @@ GByteArray* g_byte_array_remove_index (GByteArray *array,
}
GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
guint index)
guint index)
{
g_array_remove_index_fast((GArray*) array, index);
return array;
}
void
g_byte_array_sort (GByteArray *array,
GCompareFunc compare_func)
{
g_array_sort ((GArray *) array, compare_func);
}
void
g_byte_array_sort_with_data (GByteArray *array,
GCompareFuncData compare_func,
gpointer user_data)
{
g_array_sort_with_data ((GArray *) array, compare_func, user_data);
}
......@@ -63,75 +63,92 @@ struct _GPtrArray
#define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &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);
GArray* g_array_sized_new (gboolean zero_terminated,
gboolean clear,
guint element_size,
guint reserved_size);
gchar* 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_insert_vals (GArray *array,
guint index,
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);
GArray* g_array_new (gboolean zero_terminated,
gboolean clear,
guint element_size);
GArray* g_array_sized_new (gboolean zero_terminated,
gboolean clear,
guint element_size,
guint reserved_size);
gchar* 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_insert_vals (GArray *array,
guint index,
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);
void g_array_sort (GArray *array,
GCompareFunc compare_func);
void g_array_sort_with_data (GArray *array,
GCompareFuncData compare_func,
gpointer user_data);
/* 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. remove_fast will again distort
* order.
*/
#define g_ptr_array_index(array,index) (array->pdata)[index]
GPtrArray* g_ptr_array_new (void);
GPtrArray* g_ptr_array_sized_new (guint reserved_size);
gpointer* g_ptr_array_free (GPtrArray *array,
gboolean free_seg);
void g_ptr_array_set_size (GPtrArray *array,
gint length);
gpointer g_ptr_array_remove_index (GPtrArray *array,
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);
#define g_ptr_array_index(array,index) (array->pdata)[index]
GPtrArray* g_ptr_array_new (void);
GPtrArray* g_ptr_array_sized_new (guint reserved_size);
gpointer* g_ptr_array_free (GPtrArray *array,
gboolean free_seg);
void g_ptr_array_set_size (GPtrArray *array,
gint length);
gpointer g_ptr_array_remove_index (GPtrArray *array,
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);
void g_ptr_array_sort (GPtrArray *array,
GCompareFunc compare_func);
void g_ptr_array_sort_with_data (GPtrArray *array,
GCompareFuncData compare_func,
gpointer user_data);
/* Byte arrays, an array of guint8. Implemented as a GArray,
* but type-safe.
*/
GByteArray* g_byte_array_new (void);
GByteArray* g_byte_array_sized_new (guint reserved_size);
guint8* 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);
GByteArray* g_byte_array_new (void);
GByteArray* g_byte_array_sized_new (guint reserved_size);
guint8* 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);
void g_byte_array_sort (GByteArray *array,
GCompareFunc compare_func);
void g_byte_array_sort_with_data (GByteArray *array,
GCompareFuncData compare_func,
gpointer user_data);
G_END_DECLS
......
......@@ -49,6 +49,7 @@
#include <gmessages.h>
#include <gnode.h>
#include <gprimes.h>
#include <gqsort.h>
#include <gquark.h>
#include <gqueue.h>
#include <grand.h>
......
......@@ -596,18 +596,26 @@ g_list_insert_sorted (GList *list,
}
static GList *
g_list_sort_merge (GList *l1,
GList *l2,
GCompareFunc compare_func)
g_list_sort_merge (GList *l1,