int main(int argc, char* argv[]) { if(argc < 2) { printf("%s\n", "Invalid arguments: <filename>"); exit(1); } Boggle boggle; clock_t timer, stop_timer; vector<string> wordlist, found_list; timer = clock(); wordlist = create_dictionary(argv[1]); stop_timer = clock(); cout << "Execution Time for Dictionary Creation: " << (double)(stop_timer - timer)/(CLOCKS_PER_SEC)<< endl; timer = clock(); found_list = word_search(SIZE, SIZE, boggle.board, wordlist); stop_timer = clock(); cout << "Execution Time for Word Search Func: " << (double)(stop_timer - timer)/(CLOCKS_PER_SEC)<< endl; print_list(found_list); return 0; }
int splitter(FILE *fp, int splitter_lines, WordNode *ExList, int num_builder, int *builder, int splitter_id) { int ch; char word[SIZE]; int i; long count=0; int end_of_line; WordNode *find=NULL; struct tms tb2; double ticspersec = (double) sysconf(_SC_CLK_TCK); // double totalTime; long desperateEffort=0; int word_came=0; ch=getc(fp); while(splitter_lines>0 && ch!=EOF) { end_of_line=0; for (i=0; i<SIZE; i++) word[i]='\0'; while( !( (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9') ) ) { if(ch=='\n') { splitter_lines--; end_of_line=1; ch=getc(fp); break; } /* if(ch=='\"') { // check if we reached end of line if( (ch=getc(fp)) == ']') { splitter_lines--; end_of_line=1; break; } else { continue; } } */ else if (ch=='\\') { if( (ch=getc(fp)) != 'n' ) continue; } ch=getc(fp); } if(end_of_line==1) { // printf("\nlines to read: %d\n\n",splitter_lines); continue; } i=0; while( (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9') ) { if(ch>='A' && ch<='Z') ch = ch + ('a' - 'A'); word[i] = ch; ch=getc(fp); i++; } // printf(".%s.\n", word ); if(strlen(word)<=1 && strcmp("a", word)!=0) continue; // If you cannot find the word in Exclusion List send word if( (find = word_search(ExList, word)) == NULL ) { count++; // printf("splitter: .%s. num: %lu\n", word, count ); fflush(stdout); int bl = hash_function(word, num_builder); int wsize = strlen(word); if( write_all( builder[bl], &wsize, sizeof(int) ) == -1 ) return -1; if( write_all( builder[bl], word, strlen(word) ) == -1 ) return -1; } } // Time used to finish end = (double) times(&tb2); totalTime = (end - start) / ticspersec; // Inform builders of end of input and send them the time of execution for(i=0; i<num_builder; i++) { int send = -1; if( write_all( builder[i], &send , sizeof(int) ) == -1 ) return -1; if( write_all( builder[i], &totalTime, sizeof(double) ) == -1 ) return -1; close(builder[i]); } // printf("\n\n%d: Splitter's Total Time: %lf secs\n", splitter_id, totalTime); printf("\n\nSplitter %d (pid: %d) : Words Written: %lu\nSplitter %d (pid: %d) : Terminating...\n", splitter_id+1, getpid(), count, splitter_id+1, getpid()); return 0; }