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
31 #include <avahi-common/gccmacro.h>
35 #define POINTER_TO_INT(p) ((int) (p))
36 #define INT_TO_POINTER(i) ((void*) (i))
38 static int compare_int(const void* a, const void* b) {
39 int i = POINTER_TO_INT(a), j = POINTER_TO_INT(b);
41 return i < j ? -1 : (i > j ? 1 : 0);
44 static int compare_ptr(const void* a, const void* b) {
45 return a < b ? -1 : (a > b ? 1 : 0);
48 static void rec(AvahiPrioQueueNode *n) {
53 assert(n->left->parent == n);
56 assert(n->right->parent == n);
59 assert(n->parent->left == n || n->parent->right == n);
61 if (n->parent->left == n)
62 assert(n->next == n->parent->right);
66 assert(n->queue->last == n);
68 if (n->parent && n->parent->left == n)
69 assert(n->parent->right == NULL);
74 int a = POINTER_TO_INT(n->parent->data), b = POINTER_TO_INT(n->data);
76 printf("%i <= %i: NO\n", a, b);
85 int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
86 AvahiPrioQueue *q, *q2;
89 q = avahi_prio_queue_new(compare_int);
90 q2 = avahi_prio_queue_new(compare_ptr);
94 for (i = 0; i < 10000; i++)
95 avahi_prio_queue_put(q2, avahi_prio_queue_put(q, INT_TO_POINTER(random() & 0xFFFF)));
101 assert(q->n_nodes == q2->n_nodes);
103 printf("%i\n", POINTER_TO_INT(((AvahiPrioQueueNode*)q2->root->data)->data));
105 avahi_prio_queue_remove(q, q2->root->data);
106 avahi_prio_queue_remove(q2, q2->root);
111 /* while (q->root) { */
112 /* int v = GPOINTER_TO_INT(q->root->data); */
114 /* printf("%i\n", v); */
115 /* avahi_prio_queue_remove(q, q->root); */
116 /* assert(v >= prev); */
120 avahi_prio_queue_free(q);