Beispiel #1
0
int main(int argc, char **argv) {
    char word[MAXWORDSIZE];
    char cmd[MAXWORDSIZE];   /* string to hold a command */
    char fname[MAXWORDSIZE]; /* name of input file */
    PAGENO i;
    int goOn;
    int  k;

    setparms(); /* reads the pagesize and the number of ptrs/postigs_record */
    dbopen();   /* opens or creates the three files (btree, postings, text) */

    goOn = TRUE;
    while (goOn) {
        printf("\n\t*** These are your commands .........\n");
        printf("\t\"C\" to scan the tree\n");
        printf("\t\"i\" to insert\n");
        printf("\t\"p\" to print a btree page\n");
        printf("\t\"s\" to search, and print the key\n");
        printf("\t\"S\" to search, and print the key, posting list pairs\n");
        printf("\t\">\" to print k successors\n");
        printf("\t\"<\" to print k predecessors\n");
        printf("\t\"T\" to print the btree in inorder format\n");
        printf("\t\"#\" to reset and print stats\n");
        printf("\t\"x\" to exit\n");
        /* printf("\"d\" to display statistics, \"c\" to clear them,\n"); */
        scanf("%s", cmd);
        assert(strlen(cmd) < MAXWORDSIZE);
        switch (cmd[0]) {
        case 'C':
            printf("\n*** Scanning... \n");
            scanTree(&printOcc);
            break;
        case 'i':
            printf("\tgive input file name: ");
            scanf("%s", fname);
            assert(strlen(fname) < MAXWORDSIZE);
            printf("\n*** Inserting %s\n", fname);
            insert(fname);
            break;
        case 's':
            printf("enter search-word: ");
            scanf("%s", word);
            assert(strlen(word) < MAXWORDSIZE);
            printf("\n*** Searching for word %s \n", word);
            search(word, FALSE);
            break;
        case 'S':
            printf("enter search-word: ");
            scanf("%s", word);
            assert(strlen(word) < MAXWORDSIZE);
            printf("\n*** Searching for word %s \n", word);
            search(word, TRUE);
            break;
        case 'p':
            printf("pagenumber=?\n");
            scanf("%s", cmd);
            assert(strlen(cmd) < MAXWORDSIZE);
            i = (PAGENO) atoi(cmd);
            printPage(i, fpbtree);
            break;
        case '>':
            printf("word=?\n");
            scanf("%s", word);
            printf("k=?\n");
            scanf("%d", &k);
            get_successors(word, k, NULL);
            break;
        case '<':
            printf("word=?\n");
            scanf("%s", word);
            printf("k=?\n");
            scanf("%d", &k);
            get_predecessors(word, k, NULL);
            break;
        case 'T':
            printf("\n*** Printing tree in order .........\n");
            PrintTreeInOrder(ROOT, 0);
            break;
        case '#':
            printf("\n");
            printFetchPageCnt();
            printf("\n...reseted FetchPage counter\n");
            break;
        case 'x':
            printf("\n*** Exiting .........\n");
            goOn = FALSE;
            break;
        default:
            printf("\n*** Illegal command \"%s\"\n", cmd);
            break;
        }
    }

    dbclose();
    return (0);
}
Beispiel #2
0
int main(int argc, char **argv) {
    char word[MAXWORDSIZE];
    char result[MAXWORDSIZE];
    char temp[MAXWORDSIZE];
    char cmd[MAXWORDSIZE];   /* string to hold a command */
    char fname[MAXWORDSIZE]; /* name of input file */
    PAGENO i;
    int goOn;
    //   int k;

    setparms(); /* reads the pagesize and the number of ptrs/postigs_record */
    dbopen();   /* opens or creates the three files (btree, postings, text) */

    goOn = TRUE;
    while (goOn) {
        printf("\n\t*** These are your commands .........\n");
        printf("\t\"C\" to scan the tree\n");
        printf("\t\"i\" to insert\n");
        printf("\t\"p\" to print a btree page\n");
        printf("\t\"s\" to search, and print the key\n");
        printf("\t\"S\" to search, and print the key, posting list pairs\n");
        printf("\t\"]\" to print next key without given prefix\n");
        printf("\t\"[\" to print previous key without given prefix\n");
        printf("\t\"T\" to print the btree in inorder format\n");
        printf("\t\"#\" to reset and print stats\n");
        printf("\t\"x\" to exit\n");
        /* printf("\"d\" to display statistics, \"c\" to clear them,\n"); */
        scanf("%s", cmd);
        assert(strlen(cmd) < MAXWORDSIZE);
        switch (cmd[0]) {
            case 'C':
                printf("\n*** Scanning... \n");
                scanTree(&printOcc);
                break;
            case 'i':
                printf("\tgive input file name: ");
                scanf("%s", fname);
                assert(strlen(fname) < MAXWORDSIZE);
                printf("\n*** Inserting %s\n", fname);
                insert(fname);
                break;
            case 's':
                printf("enter search-word: ");
                scanf("%s", word);
                assert(strlen(word) < MAXWORDSIZE);
                printf("\n*** Searching for word %s \n", word);
                search(word, FALSE);
                break;
            case 'S':
                printf("enter search-word: ");
                scanf("%s", word);
                assert(strlen(word) < MAXWORDSIZE);
                printf("\n*** Searching for word %s \n", word);
                search(word, TRUE);
                break;
            case 'p':
                printf("pagenumber=?\n");
                scanf("%s", cmd);
                assert(strlen(cmd) < MAXWORDSIZE);
                i = (PAGENO) atoi(cmd);
                printPage(i, fpbtree);
                break;
            case ']':
                printf("word=?\n");
                scanf("%s", word);
                assert(strlen(word) < MAXWORDSIZE);
                strcpy(temp, word);;
                get_rightbracket(word, result);
                printf("Right bracket of %s:\n%s\n", temp,result);
                break; 
            case '[':
                printf("word=?\n");
                scanf("%s", word);
                assert(strlen(word) < MAXWORDSIZE);
              //  strcpy(temp, word);;
                get_leftbracket(word, result);
                printf("Left bracket of %s:\n%s\n", word,result);
                break; 
                break;
            case 'T':
                printf("\n*** Printing tree in order .........\n");
                PrintTreeInOrder(ROOT, 0);
                break;
            case '#':
                printf("\n*** #of reads on B-tree: %d", countPageFetch);
                countPageFetch = 0;
                break;
            case 'x':
                printf("\n*** Exiting .........\n");
                goOn = FALSE;
                break;
            default:
                printf("\n*** Illegal command \"%s\"\n", cmd);
                break;
        }
    }

    dbclose();
    return (0);
}