mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-05 02:36:19 +01:00
- Call g_queue_insert_sorted() instead of duplicating the code. - Call
* glib/gasyncqueue.c: - Call g_queue_insert_sorted() instead of duplicating the code. - Call g_queue_sort() instead of duplicating the code. - Invert sort function results to make sure the same sort function gives the same results across glist, gslist, gqueue and gasyncqueue. * tests/asyncqueue-test.c: - Updated the sort function to reflect the example in the documentation for gasyncqueue.c.
This commit is contained in:
parent
9763367246
commit
c6ad7b7ac8
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
2005-12-07 Martyn Russell <martyn@imendio.com>
|
||||||
|
|
||||||
|
* glib/gasyncqueue.c:
|
||||||
|
- Call g_queue_insert_sorted() instead of duplicating the code.
|
||||||
|
- Call g_queue_sort() instead of duplicating the code.
|
||||||
|
- Invert sort function results to make sure the same sort function
|
||||||
|
gives the same results across glist, gslist, gqueue and
|
||||||
|
gasyncqueue.
|
||||||
|
|
||||||
|
* tests/asyncqueue-test.c:
|
||||||
|
- Updated the sort function to reflect the example in the
|
||||||
|
documentation for gasyncqueue.c.
|
||||||
|
|
||||||
2005-12-07 Martyn Russell <martyn@imendio.com>
|
2005-12-07 Martyn Russell <martyn@imendio.com>
|
||||||
|
|
||||||
* docs/reference/glib/glib-sections.txt:
|
* docs/reference/glib/glib-sections.txt:
|
||||||
|
@ -1,3 +1,16 @@
|
|||||||
|
2005-12-07 Martyn Russell <martyn@imendio.com>
|
||||||
|
|
||||||
|
* glib/gasyncqueue.c:
|
||||||
|
- Call g_queue_insert_sorted() instead of duplicating the code.
|
||||||
|
- Call g_queue_sort() instead of duplicating the code.
|
||||||
|
- Invert sort function results to make sure the same sort function
|
||||||
|
gives the same results across glist, gslist, gqueue and
|
||||||
|
gasyncqueue.
|
||||||
|
|
||||||
|
* tests/asyncqueue-test.c:
|
||||||
|
- Updated the sort function to reflect the example in the
|
||||||
|
documentation for gasyncqueue.c.
|
||||||
|
|
||||||
2005-12-07 Martyn Russell <martyn@imendio.com>
|
2005-12-07 Martyn Russell <martyn@imendio.com>
|
||||||
|
|
||||||
* docs/reference/glib/glib-sections.txt:
|
* docs/reference/glib/glib-sections.txt:
|
||||||
|
@ -1,3 +1,16 @@
|
|||||||
|
2005-12-07 Martyn Russell <martyn@imendio.com>
|
||||||
|
|
||||||
|
* glib/gasyncqueue.c:
|
||||||
|
- Call g_queue_insert_sorted() instead of duplicating the code.
|
||||||
|
- Call g_queue_sort() instead of duplicating the code.
|
||||||
|
- Invert sort function results to make sure the same sort function
|
||||||
|
gives the same results across glist, gslist, gqueue and
|
||||||
|
gasyncqueue.
|
||||||
|
|
||||||
|
* tests/asyncqueue-test.c:
|
||||||
|
- Updated the sort function to reflect the example in the
|
||||||
|
documentation for gasyncqueue.c.
|
||||||
|
|
||||||
2005-12-07 Martyn Russell <martyn@imendio.com>
|
2005-12-07 Martyn Russell <martyn@imendio.com>
|
||||||
|
|
||||||
* docs/reference/glib/glib-sections.txt:
|
* docs/reference/glib/glib-sections.txt:
|
||||||
|
@ -39,6 +39,11 @@ struct _GAsyncQueue
|
|||||||
gint32 ref_count;
|
gint32 ref_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GCompareDataFunc func;
|
||||||
|
gpointer user_data;
|
||||||
|
} SortData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_async_queue_new:
|
* g_async_queue_new:
|
||||||
*
|
*
|
||||||
@ -255,6 +260,14 @@ g_async_queue_push_sorted (GAsyncQueue *queue,
|
|||||||
g_mutex_unlock (queue->mutex);
|
g_mutex_unlock (queue->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gint
|
||||||
|
g_async_queue_invert_compare (gpointer v1,
|
||||||
|
gpointer v2,
|
||||||
|
SortData *sd)
|
||||||
|
{
|
||||||
|
return -sd->func (v1, v2, sd->user_data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_async_queue_push_sorted_unlocked:
|
* g_async_queue_push_sorted_unlocked:
|
||||||
* @queue: a #GAsyncQueue
|
* @queue: a #GAsyncQueue
|
||||||
@ -284,21 +297,17 @@ g_async_queue_push_sorted_unlocked (GAsyncQueue *queue,
|
|||||||
GCompareDataFunc func,
|
GCompareDataFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GQueue *q;
|
SortData sd;
|
||||||
GList *list;
|
|
||||||
|
|
||||||
g_return_if_fail (queue != NULL);
|
g_return_if_fail (queue != NULL);
|
||||||
|
|
||||||
q = queue->queue;
|
sd.func = func;
|
||||||
|
sd.user_data = user_data;
|
||||||
|
|
||||||
list = q->head;
|
g_queue_insert_sorted (queue->queue,
|
||||||
while (list && func (list->data, data, user_data) < 0)
|
data,
|
||||||
list = list->next;
|
(GCompareDataFunc)g_async_queue_invert_compare,
|
||||||
|
&sd);
|
||||||
if (list)
|
|
||||||
g_queue_insert_before (q, list, data);
|
|
||||||
else
|
|
||||||
g_queue_push_tail (q, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
@ -554,13 +563,13 @@ g_async_queue_length_unlocked (GAsyncQueue* queue)
|
|||||||
* If you were sorting a list of priority numbers to make sure the
|
* If you were sorting a list of priority numbers to make sure the
|
||||||
* lowest priority would be at the top of the queue, you could use:
|
* lowest priority would be at the top of the queue, you could use:
|
||||||
* <informalexample><programlisting>
|
* <informalexample><programlisting>
|
||||||
* gint id1;
|
* gint32 id1;
|
||||||
* gint id2;
|
* gint32 id2;
|
||||||
*
|
*
|
||||||
* id1 = GPOINTER_TO_INT (element1);
|
* id1 = GPOINTER_TO_INT (element1);
|
||||||
* id2 = GPOINTER_TO_INT (element2);
|
* id2 = GPOINTER_TO_INT (element2);
|
||||||
*
|
*
|
||||||
* return (id2 - id1);
|
* return (id1 > id2 ? +1 : id1 == id2 ? 0 : -1);
|
||||||
* </programlisting></informalexample>
|
* </programlisting></informalexample>
|
||||||
*
|
*
|
||||||
* Since: 2.10
|
* Since: 2.10
|
||||||
@ -600,17 +609,18 @@ g_async_queue_sort_unlocked (GAsyncQueue *queue,
|
|||||||
GCompareDataFunc func,
|
GCompareDataFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GQueue *q;
|
SortData sd;
|
||||||
|
|
||||||
g_return_if_fail (queue != NULL);
|
g_return_if_fail (queue != NULL);
|
||||||
g_return_if_fail (func != NULL);
|
g_return_if_fail (func != NULL);
|
||||||
|
|
||||||
q = queue->queue;
|
sd.func = func;
|
||||||
|
sd.user_data = user_data;
|
||||||
|
|
||||||
q->head = g_list_sort_with_data (q->head, func, user_data);
|
g_queue_sort (queue->queue,
|
||||||
q->tail = g_list_last (q->head);
|
(GCompareDataFunc)g_async_queue_invert_compare,
|
||||||
|
&sd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define __G_ASYNCQUEUE_C__
|
#define __G_ASYNCQUEUE_C__
|
||||||
#include "galiasdef.c"
|
#include "galiasdef.c"
|
||||||
|
@ -37,16 +37,16 @@ static GAsyncQueue *async_queue = NULL;
|
|||||||
static gint
|
static gint
|
||||||
sort_compare (gconstpointer p1, gconstpointer p2, gpointer user_data)
|
sort_compare (gconstpointer p1, gconstpointer p2, gpointer user_data)
|
||||||
{
|
{
|
||||||
gint id1;
|
gint32 id1;
|
||||||
gint id2;
|
gint32 id2;
|
||||||
|
|
||||||
id1 = GPOINTER_TO_INT (p1);
|
id1 = GPOINTER_TO_INT (p1);
|
||||||
id2 = GPOINTER_TO_INT (p2);
|
id2 = GPOINTER_TO_INT (p2);
|
||||||
|
|
||||||
d(g_print ("comparing #1:%d and #2:%d, returning %d\n",
|
d(g_print ("comparing #1:%d and #2:%d, returning %d\n",
|
||||||
id1, id2, (id2 - id1)));
|
id1, id2, (id1 > id2 ? +1 : id1 == id2 ? 0 : -1)));
|
||||||
|
|
||||||
return (id2 - id1);
|
return (id1 > id2 ? +1 : id1 == id2 ? 0 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
Loading…
Reference in New Issue
Block a user