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
33 #define POINTER_TO_INT(p) ((int) (p))
34 #define INT_TO_POINTER(i) ((void*) (i))
36 static int compare_int(const void* a, const void* b) {
37 int i = POINTER_TO_INT(a), j = POINTER_TO_INT(b);
39 return i < j ? -1 : (i > j ? 1 : 0);
42 static int compare_ptr(const void* a, const void* b) {
43 return a < b ? -1 : (a > b ? 1 : 0);
46 static void rec(AvahiPrioQueueNode *n) {
51 assert(n->left->parent == n);
54 assert(n->right->parent == n);
57 assert(n->parent->left == n || n->parent->right == n);
59 if (n->parent->left == n)
60 assert(n->next == n->parent->right);
64 assert(n->queue->last == n);
66 if (n->parent && n->parent->left == n)
67 assert(n->parent->right == NULL);
72 int a = POINTER_TO_INT(n->parent->data), b = POINTER_TO_INT(n->data);
74 printf("%i <= %i: NO\n", a, b);
83 int main(int argc, char *argv[]) {
84 AvahiPrioQueue *q, *q2;
87 q = avahi_prio_queue_new(compare_int);
88 q2 = avahi_prio_queue_new(compare_ptr);
92 for (i = 0; i < 10000; i++)
93 avahi_prio_queue_put(q2, avahi_prio_queue_put(q, INT_TO_POINTER(random() & 0xFFFF)));
99 assert(q->n_nodes == q2->n_nodes);
101 printf("%i\n", POINTER_TO_INT(((AvahiPrioQueueNode*)q2->root->data)->data));
103 avahi_prio_queue_remove(q, q2->root->data);
104 avahi_prio_queue_remove(q2, q2->root);
109 /* while (q->root) { */
110 /* int v = GPOINTER_TO_INT(q->root->data); */
112 /* printf("%i\n", v); */
113 /* avahi_prio_queue_remove(q, q->root); */
114 /* assert(v >= prev); */
118 avahi_prio_queue_free(q);