int main()
{
int i;
wrapdata *node;
data *newdata;
int count;
int word_count;
int word_buffer[RAND]={0};
FILE *fp = NULL;
char buffer[64] = "";
uint value = 0;
char *pvalue = NULL;
int weight = 0;
int ikeylen = 0;
char strFilePath[128] = "";
char buf[100]="";
unsigned char word[100]="\0";
int gbk=0;
init();
srand(time(NULL));
node=(wrapdata*)calloc (1 ,sizeof (wrapdata));
global_node=node;
getcwd(buf, sizeof(buf)-1);
sprintf(strFilePath, "%s/%s", buf ,"single.txt");
fp = fopen(strFilePath, "rt");
word_count=0;
while (fgets(buffer, sizeof(buffer) - 1, fp) > 0)
{
pvalue = (char *)memchr(buffer, '\t', sizeof(buffer));
ikeylen = (pvalue - buffer);
memcpy( word ,buffer ,ikeylen);
// printf("add word %s ",buffer);
gbk=word[0] * 256 + word[1];
insert(node ,gbk);
word_buffer[word_count++]=gbk;
}
fclose(fp);
while(1)
{
// printf("into insert mode\n");
while( node->size< word_count)
{
i=rand()%word_count;
insert (node ,word_buffer[i] );
count=check(node->root);
if(count)
{
// printf("\ncheck error\n");
// mid_print(node->root,0);
return ;
}
/*
count=mid_print (node->root,0);
if(count!=node->size)
{
// printf("\n %d %d \n",count ,node->size);
return ;
}
*/
if(error_label)
{
return ;
}
if(node->size==word_count*2/3)
{
// mid_print(node->root,0);
printf("%d %d \n",node->size,depth (node->root));
}
}
// mid_print(node->root,0);
// printf("into delete mode\n");
while( node->size> word_count/2)
{
i=rand()%word_count;
delete (node ,word_buffer[i] );
count=check(node->root);
if(count)
{
// printf("\ncheck error\n");
return ;
}
/*
count=mid_print (node->root,0);
if(count!=node->size)
{
// printf("\n delete error %d %d \n",count ,node->size);
return ;
}
*/
if(error_label)
{
return ;
}
if(node->size==word_count*2/3)
{
// mid_print(node->root,0);
printf("%d %d \n",node->size,depth (node->root));
}
}
}
return 0;
}