/* Author J. Zobel, August 2001. Permission to use this code is freely granted, provided that this statement is retained. */ /* Ternary quick sort */ #include #include #include #include char *malloc(); void exit(); #define THRESHOLD 314 typedef struct trierec { struct trierec *ptrs[128]; short counts[128]; } TRIE; typedef struct listrec { char *word; struct listrec *next; } LIST; void ternaryqsort(char **, int); void burstinsert(char *, TRIE *, LIST *); int bursttraverse(TRIE *, char **, int, int); int cmpit(); int scmp(char *, char *); int main(int argc, char *argv[]) { FILE *fp, *fopen(); int c; int i, k, ccnt, scnt; char **thestrings; char *tmp, *ptr; if( argc == 1 ) /* reading from standard input */ { fprintf(stderr, "Usage: burstsort filename\n"); exit(1); } else { if( ( fp = fopen(argv[1], "r") ) == NULL ) { fprintf(stderr, "%s: file not found.\n", argv[1]); exit(1); } } /* how big is the file, how many strings? */ for( ccnt=scnt=0 ; ( c = getc(fp) ) != EOF ; ccnt++ ) { if( c=='\n' ) scnt++; } /* fprintf(stderr, "found %d strings\n", scnt); */ /* load the strings */ thestrings = (char **) malloc(sizeof(char *) * ( scnt+1 )); tmp = (char *) malloc(sizeof(char) * ccnt); rewind(fp); fread(tmp, sizeof(char), ccnt, fp); thestrings[0] = tmp; for( k=i=0 ; i=up ) return; ltup = low; gtlow = up; mid = ( strings[up][pos]+strings[low][pos] ) /2; for( curr=ltup ; curr<=gtlow ; ) { if( ( c=strings[curr][pos] )ltup ) { tmp = strings[curr]; strings[curr] = strings[ltup]; strings[ltup] = tmp; } ltup++; curr++; } else if( c>mid ) { /* if( curr