示例#1
0
文件: main.c 项目: simplex1337/saod
int main()
{
    FILE *data = fopen("base.txt", "r");
    int i, n;
    for (i = 0; i < 200000; i++)
        fscanf(data, "%s\n", word[i]);
    fclose(data);
    struct bstree *tree;
    tree = bstree_create(word[0], 0);  
    for (i = 2; i <= 200000; i++) {
        bstree_add(tree, word[i - 1], i - 1);
        if (i % 10000 == 0)
            for (n = 0; n < 100; n++) {
                sleep(1);
                char *w = word[getrand(0, i - 1)];
                printf("%s\n", w);
                double t = wtime();
                struct bstree *node = bstree_lookup(tree, w);
                t = wtime() - t;
                printf("%s\n", node->key);
                printf("n = %d; time = %.6f\n", i, t);
                FILE *log = fopen("bstree_1.log", "a");
                fprintf(log, "%d\t%.6f\n", i, t);
                fclose(log);
            }
    }
    return 0;
}
示例#2
0
int main(int argc, char *argv[]) {
	
	FILE *f = fopen("test_look.txt", "a");
      
    FILE *dictionary = fopen("text.txt", "r");
    
    
    int i;
    int size = atoi(argv[1]);
    srand(time(NULL));
    int rand_node = rand() % size;
    
    //printf("%d\n", rand_node);
    

    char *rand_data = malloc(sizeof(char)*100);
    bstree *tree;
    
    
    for (i = 0; i < size; i++)
    {
		char *ftemp = malloc(sizeof(char)*100);
        fscanf(dictionary, "%s\n", ftemp);
        
        if (i == 0)
			tree = bstree_create(ftemp, i);
		else
			bstree_add(tree, ftemp, i);
			
  
        
        if (i == rand_node)
        {
            strcpy(rand_data, ftemp);
        }
    }
    //printf("%s\n", rand_data);
    
    
    bstree *lkt ;
    double t = clock();
    lkt = bstree_lookup(tree, rand_data);
    fprintf(f, "%d\t%.8f\n", size, (clock() - t) / CLOCKS_PER_SEC);
    printf("%s %d\n", lkt->key, lkt->value);
    
    
    fclose(f);
    fclose(dictionary);
	 
return 0;
}