2 * GQueue, opaque ADT with interface:
5 count = g_queue_size (q);
7 q_queue_push_front (q, data);
8 q_queue_push_back (q, data);
9 data = q_queue_pop_front (q);
10 data = q_queue_pop_back (q);
11 #define q_queue_push q_queue_push_back
12 #define q_queue_pop q_queue_pop_front
14 list = g_queue_get_list (q);
15 #define g_queue_get_front g_queue_get_list
16 list_end = g_queue_get_back (q);
32 GQueue *q = g_new (GQueue, 1);
34 q->list = q->list_end = NULL;
42 g_queue_free (GQueue *q)
46 g_list_free (q->list);
53 g_queue_get_size (GQueue *q)
55 return (q == NULL) ? 0 : q->list_size;
60 g_queue_push_front (GQueue *q, gpointer data)
63 q->list = g_list_prepend (q->list, data);
65 if (q->list_end == NULL)
66 q->list_end = q->list;
74 g_queue_push_back (GQueue *q, gpointer data)
77 q->list_end = g_list_append (q->list_end, data);
80 q->list = q->list_end;
82 q->list_end = q->list_end->next;
90 g_queue_pop_front (GQueue *q)
94 if ((q) && (q->list)) {
101 q->list = q->list_end = NULL;
105 q->list = node->next;
106 q->list->prev = NULL;
110 g_list_free_1 (node);
118 g_queue_pop_back (GQueue *q)
120 gpointer data = NULL;
122 if ((q) && (q->list)) {
129 q->list = q->list_end = NULL;
133 q->list_end = node->prev;
134 q->list_end->next = NULL;
138 g_list_free_1 (node);