#include <stdio.h>
#include <stdlib.h>

#include "btree64k.h"

struct test_s {
   char data[8];
   };
typedef struct test_s Test;

int main()
   {
   BTree *tree;
   SList *list;
   Test test;
   Test *test2;
   Test *test3;
   int a;
   int b;

   BT_SetBTAttributes(8, 4);
   tree = BT_Init(1000000);
   for (a = 1; a < 1000001; ++a)
      {
      for (b = 0; b < 4; ++b)
         {
         test.data[b] = rand() % 26 + 'A';
         test.data[b + 4] = test.data[b] - 'A' + 'a';
         }
      test.data[7] = 0;
      if (test.data[0] == 'A' && test.data[1] == 'A' && test.data[3] == 'A')
         printf("%s\n", test.data);
      BT_AddEntry(tree, &test, 0);
      if (!(a % 100000))
         printf("%d created, %d added\n", a, BT_NumEntries(tree));
      }
   printf("starting convert\n");
   list = SL_Init(tree);
   printf("finished convert\n");
   test.data[0] = 'A';
   test.data[1] = 'A';
   test.data[3] = 'A';
   for (a = 'A'; a <= 'Z'; ++a)
      {
      test.data[2] = a;
      test2 = BT_FindEntry(tree, &test);
      test3 = SL_FindEntry(list, &test);

      if (test2 || test3)
         {
         if (test2)
            printf("%s  ", test2->data);
         else
            printf("xxxxxxx  ");
         
         if (test3)
            printf("%s\n", test3->data);
         else
            printf("xxxxxxx\n");
         }
      }
   return 1;
   }

