]> git.meshlink.io Git - catta/blob - prioq-test.c
add infrastrtcur for creating and sending DNS packets
[catta] / prioq-test.c
1 #include <time.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 #include "prioq.h"
6
7 static gint compare(gconstpointer a, gconstpointer b) {
8     gint i = GPOINTER_TO_INT(a), j = GPOINTER_TO_INT(b);
9
10     return i < j ? -1 : (i > j ? 1 : 0);
11 }
12
13 static void rec(flxPrioQueueNode *n) {
14     if (!n)
15         return;
16
17     if (n->parent) {
18         int a = GPOINTER_TO_INT(n->parent->data), b = GPOINTER_TO_INT(n->data);
19         if (a > b) {
20             printf("%i <= %i: NO\n", a, b);
21             abort();
22         }
23     }
24
25     rec(n->left);
26     rec(n->right);
27 }
28
29 int main(int argc, char *argv[]) {
30     flxPrioQueue *q;
31     gint i, prev;
32
33     q = flx_prio_queue_new(compare);
34
35     srand(time(NULL));
36
37     flx_prio_queue_put(q, GINT_TO_POINTER(255)); 
38     flx_prio_queue_put(q, GINT_TO_POINTER(255)); 
39     
40     for (i = 0; i < 10000; i++) 
41         flx_prio_queue_put(q, GINT_TO_POINTER(random() & 0xFFFF)); 
42
43     prev = 0;
44     while (q->root) {
45         gint v = GPOINTER_TO_INT(q->root->data);
46         rec(q->root);
47         printf("%i\n", v);
48         flx_prio_queue_remove(q, q->root);
49         g_assert(v >= prev);
50         prev = v;
51     }
52
53     flx_prio_queue_free(q);
54     return 0;
55 }