]> mj.ucw.cz Git - libucw.git/blobdiff - lib/binheap-test.c
One more deadly testcase.
[libucw.git] / lib / binheap-test.c
index 703fac87980b0f58f635c88c595db23bc7b1faaa..2a0f026f4447023ba3a54e554b816dda34dd7a70 100644 (file)
 #include "lib/binheap-node.h"
 
 struct item {
 #include "lib/binheap-node.h"
 
 struct item {
-  struct bht_node n;
+  struct bh_node n;
   uns key;
 };
 
   uns key;
 };
 
-static inline uns bht_key(struct bht_node *n)
+static inline uns bht_key(struct bh_node *n)
 {
   return ((struct item *)n)->key;
 }
 
 {
   return ((struct item *)n)->key;
 }
 
-static inline uns bht_less(struct bht_node *a, struct bht_node *b)
+static inline uns bht_less(struct bh_node *a, struct bh_node *b)
 {
   return bht_key(a) < bht_key(b);
 }
 
 static void
 {
   return bht_key(a) < bht_key(b);
 }
 
 static void
-bht_do_dump(struct bht_node *a, struct bht_node *expected_last, uns offset)
+bht_do_dump(struct bh_node *a, struct bh_node *expected_last, uns offset)
 {
   if (!a)
     return;
   printf("%*s", offset, "");
   printf("[%d](%d)%s\n", a->order, bht_key(a), a == expected_last ? " L" : "");
 {
   if (!a)
     return;
   printf("%*s", offset, "");
   printf("[%d](%d)%s\n", a->order, bht_key(a), a == expected_last ? " L" : "");
-  for (struct bht_node *b=a->first_son; b; b=b->next_sibling)
+  for (struct bh_node *b=a->first_son; b; b=b->next_sibling)
     bht_do_dump(b, a->last_son, offset+1);
 }
 
 static void
     bht_do_dump(b, a->last_son, offset+1);
 }
 
 static void
-bht_dump(struct bht_heap *h)
+bht_dump(struct bh_heap *h)
 {
   printf("root\n");
 {
   printf("root\n");
-  for (struct bht_node *b=h->root.first_son; b; b=b->next_sibling)
+  for (struct bh_node *b=h->root.first_son; b; b=b->next_sibling)
     bht_do_dump(b, b->last_son, 1);
 }
 
     bht_do_dump(b, b->last_son, 1);
 }
 
@@ -57,7 +57,7 @@ bht_dump(struct bht_heap *h)
 int main(void)
 {
   uns i;
 int main(void)
 {
   uns i;
-  struct bht_heap h;
+  struct bh_heap h;
 #define N 1048576
 #define K(i) ((259309*i+1009)%N)
 
 #define N 1048576
 #define K(i) ((259309*i+1009)%N)
 
@@ -71,8 +71,16 @@ int main(void)
       bht_insert(&h, &a->n);
       // bht_dump(&h);
     }
       bht_insert(&h, &a->n);
       // bht_dump(&h);
     }
-  bht_dump(&h);
+  // bht_dump(&h);
   ASSERT(bht_key(bht_findmin(&h)) == 0);
   ASSERT(bht_key(bht_findmin(&h)) == 0);
+  uns cnt = 0;
+  BH_FOR_ALL(bht_, &h, a)
+    {
+      cnt++;
+    }
+  BH_END_FOR;
+  printf("cnt=%d\n", cnt);
+  ASSERT(cnt == N);
   for (i=0; i<N; i++)
     {
       struct item *a = (struct item *) bht_deletemin(&h);
   for (i=0; i<N; i++)
     {
       struct item *a = (struct item *) bht_deletemin(&h);