/* * if the file named by fp exists * TODO : performance ??? */ int isExistsFile(char *fname){ char path[MAXLINE]; path[0] = '\0'; // if not exist in bloom filter, then file is new if(bloom_on){ if(bloom_filter_contains(filter, fname) == 0) return 0; } strcat(path, STORE_PREFIX); strcat(path, fname); if((access(path, F_OK)) != -1) return 1; else return 0; }
/** * Ad-hoc command-line spell checker */ int main(int argc, char *argv[]) { // Open the dictionary file FILE *fp; if (!(fp = fopen("dictionary", "r"))) { fprintf(stderr, "E: Couldn't open words file\n"); fflush (stderr); return 1; } // Create a bloom filter bloom_t *filter = bloom_filter_new(2500000); // Add all dictionary words to the filter char *p; char line[1024]; while (fgets(line, 1024, fp)) { strip(line); bloom_filter_add(filter, line); } fclose(fp); printf("bloom filter count : %u\n", bloom_filter_count(filter)); printf("bloom filter size : %u\n", bloom_filter_size(filter)); // Read words from stdin and print those words not in the bloom filter while (fgets(line, 1024, stdin)) { strip(line); p = strtok(line, " \t,.;:\r\n?!-/()"); while (p) { if (!bloom_filter_contains(filter, p)) { printf("%s\n", p); } p = strtok(NULL, " \t,.;:\r\n?!-/()"); } } // Cleanup bloom_filter_free(filter); return 0; }