2 * UCW Library -- Binomial Heaps: Testing
4 * (c) 2003 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
15 #define BH_PREFIX(x) bht_##x
16 #define BH_WANT_INSERT
17 #define BH_WANT_FINDMIN
18 #define BH_WANT_DELETEMIN
19 #include "lib/binheap-node.h"
26 static inline uns bht_key(struct bh_node *n)
28 return ((struct item *)n)->key;
31 static inline uns bht_less(struct bh_node *a, struct bh_node *b)
33 return bht_key(a) < bht_key(b);
37 bht_do_dump(struct bh_node *a, struct bh_node *expected_last, uns offset)
41 printf("%*s", offset, "");
42 printf("[%d](%d)%s\n", a->order, bht_key(a), a == expected_last ? " L" : "");
43 for (struct bh_node *b=a->first_son; b; b=b->next_sibling)
44 bht_do_dump(b, a->last_son, offset+1);
48 bht_dump(struct bh_heap *h)
51 for (struct bh_node *b=h->root.first_son; b; b=b->next_sibling)
52 bht_do_dump(b, b->last_son, 1);
55 #include "lib/binheap.h"
62 #define K(i) ((259309*i+1009)%N)
68 struct item *a = xmalloc_zero(sizeof(*a));
70 // printf("Insert %d\n", a->key);
71 bht_insert(&h, &a->n);
75 ASSERT(bht_key(bht_findmin(&h)) == 0);
77 BH_FOR_ALL(bht_, &h, a)
82 printf("cnt=%d\n", cnt);
86 struct item *a = (struct item *) bht_deletemin(&h);
87 // printf("\nDeleted %d:\n", a->key);