#include #include #include #define MAXWLEN 20 #define CLSIZE 1024 #define EPERCLUST 42 /* pack 42 elements per cluster */ struct element { /* each element is a word and count or a word index */ int count; /* dual use field - cluster index or word count */ char word[MAXWLEN]; }; struct cluster { /* use the same cluster struct for index or words */ int isindexcluster; /* set to 1 for index clust, 0 for words */ struct element elem[EPERCLUST]; } clust; char *file_name = "isamfile"; main(int argc, char *argv[]) { int i, j, n, fd; fd = open(file_name, O_RDONLY); /* open the file for reading */ if(fd < 0) { fprintf(stderr, "Could not open %s\n", file_name); exit(1); } for(i = 0; ; i++) { lseek(fd, i*CLSIZE, 0); n = read(fd, &clust, sizeof(struct cluster)); if(n <= 0) break; printf("----------- cluster %d is %s cluster --------\n", i, clust.isindexcluster ? "an index" : "a word count"); for(j = 0; j < EPERCLUST; j++) { printf("%d.%d <%s> %d\n", i, j, clust.elem[j].word, clust.elem[j].count); if(clust.elem[j].word[0] == 0) break; } } printf("read %d clusters\n", i); }