4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 static gint compare_int(gconstpointer a, gconstpointer b) {
33 gint i = GPOINTER_TO_INT(a), j = GPOINTER_TO_INT(b);
35 return i < j ? -1 : (i > j ? 1 : 0);
38 static int compare_ptr(gconstpointer a, gconstpointer b) {
39 return a < b ? -1 : (a > b ? 1 : 0);
42 static void rec(AvahiPrioQueueNode *n) {
47 g_assert(n->left->parent == n);
50 g_assert(n->right->parent == n);
53 g_assert(n->parent->left == n || n->parent->right == n);
55 if (n->parent->left == n)
56 g_assert(n->next == n->parent->right);
60 g_assert(n->queue->last == n);
62 if (n->parent && n->parent->left == n)
63 g_assert(n->parent->right == NULL);
68 int a = GPOINTER_TO_INT(n->parent->data), b = GPOINTER_TO_INT(n->data);
70 printf("%i <= %i: NO\n", a, b);
79 int main(int argc, char *argv[]) {
80 AvahiPrioQueue *q, *q2;
83 q = avahi_prio_queue_new(compare_int);
84 q2 = avahi_prio_queue_new(compare_ptr);
88 for (i = 0; i < 10000; i++)
89 avahi_prio_queue_put(q2, avahi_prio_queue_put(q, GINT_TO_POINTER(random() & 0xFFFF)));
95 g_assert(q->n_nodes == q2->n_nodes);
97 printf("%i\n", GPOINTER_TO_INT(((AvahiPrioQueueNode*)q2->root->data)->data));
99 avahi_prio_queue_remove(q, q2->root->data);
100 avahi_prio_queue_remove(q2, q2->root);
105 /* while (q->root) { */
106 /* gint v = GPOINTER_TO_INT(q->root->data); */
108 /* printf("%i\n", v); */
109 /* avahi_prio_queue_remove(q, q->root); */
110 /* g_assert(v >= prev); */
114 avahi_prio_queue_free(q);