6 xbinheap_handler *handlers;
7 int test1(unsigned long n)
12 handlers = malloc(sizeof(xbinheap_handler) * n);
13 xbinheap_init(&h, n, XBINHEAP_MAX, NULL);
14 for (i = 0; i < n; i++) {
15 handlers[i] = xbinheap_insert(&h, i, i);
16 if (handlers[i] == NoNode){
17 fprintf(stderr, "Error inserting %llu\n", i);
21 for (j = n-1; j >=0; j--) {
23 r = xbinheap_extract(&h);
25 fprintf(stderr, "Extracted invalid value %llu != %llu\n", r, i);
29 for (i = 0; i < n; i++) {
30 handlers[i] = xbinheap_insert(&h, i, i);
32 xbinheap_increasekey(&h, handlers[0], n);
33 r = xbinheap_extract(&h);
35 fprintf(stderr, "Extracted invalid value after increase %llu != 0\n", r);
38 handlers[0] = xbinheap_insert(&h, n+1, n+1);
39 printf("handler[0]: %llu\n", handlers[0]);
40 r = xbinheap_getkey(&h, handlers[0]);
42 fprintf(stderr, "getkey: got %llu, instead of %lu\n", r, n+1);
45 r = xbinheap_peak(&h);
47 fprintf(stderr, "peak: got %llu, expected %llu", r, n+1);
51 xbinheap_decreasekey(&h, handlers[0], 0);
53 r = xbinheap_getkey(&h, handlers[0]);
55 fprintf(stderr, "getkey: got %llu, instead of 0\n", r);
58 r = xbinheap_peak(&h);
60 fprintf(stderr, "peak: got %llu, expected diffrent", n+1);
69 int main(int argc, const char *argv[])
71 struct timeval start, end, tv;
73 int n = atoi(argv[1]);
75 fprintf(stderr, "Running test1\n");
76 gettimeofday(&start, NULL);
79 fprintf(stderr, "Test1: FAILED\n");
82 gettimeofday(&end, NULL);
83 timersub(&end, &start, &tv);
84 fprintf(stderr, "Test1: PASSED\n");
85 fprintf(stderr, "Test time: %ds %dusec\n\n", (int)tv.tv_sec, (int)tv.tv_usec);