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
28 static gint compare_int(gconstpointer a, gconstpointer b) {
29 gint i = GPOINTER_TO_INT(a), j = GPOINTER_TO_INT(b);
31 return i < j ? -1 : (i > j ? 1 : 0);
34 static int compare_ptr(gconstpointer a, gconstpointer b) {
35 return a < b ? -1 : (a > b ? 1 : 0);
38 static void rec(AvahiPrioQueueNode *n) {
43 g_assert(n->left->parent == n);
46 g_assert(n->right->parent == n);
49 g_assert(n->parent->left == n || n->parent->right == n);
51 if (n->parent->left == n)
52 g_assert(n->next == n->parent->right);
56 g_assert(n->queue->last == n);
58 if (n->parent && n->parent->left == n)
59 g_assert(n->parent->right == NULL);
64 int a = GPOINTER_TO_INT(n->parent->data), b = GPOINTER_TO_INT(n->data);
66 printf("%i <= %i: NO\n", a, b);
75 int main(int argc, char *argv[]) {
76 AvahiPrioQueue *q, *q2;
79 q = avahi_prio_queue_new(compare_int);
80 q2 = avahi_prio_queue_new(compare_ptr);
84 for (i = 0; i < 10000; i++)
85 avahi_prio_queue_put(q2, avahi_prio_queue_put(q, GINT_TO_POINTER(random() & 0xFFFF)));
91 g_assert(q->n_nodes == q2->n_nodes);
93 printf("%i\n", GPOINTER_TO_INT(((AvahiPrioQueueNode*)q2->root->data)->data));
95 avahi_prio_queue_remove(q, q2->root->data);
96 avahi_prio_queue_remove(q2, q2->root);
101 /* while (q->root) { */
102 /* gint v = GPOINTER_TO_INT(q->root->data); */
104 /* printf("%i\n", v); */
105 /* avahi_prio_queue_remove(q, q->root); */
106 /* g_assert(v >= prev); */
110 avahi_prio_queue_free(q);