Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-04 05:19:05

0001 #include <stdio.h>
0002 #include <string.h>
0003 #include <sys/types.h>
0004 #include <sys/stat.h>
0005 #include <fcntl.h>
0006 #include <stdlib.h>
0007 
0008 #include "dablooms.h"
0009 
0010 #define CAPACITY 5000
0011 #define ERROR_RATE 0.0002
0012 
0013 static void chomp_line(char *word) {
0014   char *p;
0015   if ((p = strchr(word, '\r'))) {
0016     *p = '\0';
0017   }
0018   if ((p = strchr(word, '\n'))) {
0019     *p = '\0';
0020   }
0021 }
0022 
0023 int generate_bloom_filter(const char *bloom_file, const char *words_file) {
0024   FILE *fp;
0025   char word[1024];
0026   scaling_bloom_t *bloom;
0027   int i;
0028 
0029   if (!(bloom = new_scaling_bloom(CAPACITY, ERROR_RATE, bloom_file))) {
0030     fprintf(stderr, "ERROR: Could not create bloom filter\n");
0031     return EXIT_FAILURE;
0032   }
0033 
0034   if (!(fp = fopen(words_file, "r"))) {
0035     fprintf(stderr, "ERROR: Could not open words file\n");
0036     return EXIT_FAILURE;
0037   }
0038 
0039   for (i = 0; fgets(word, sizeof(word), fp); i++) {
0040     chomp_line(word);
0041     scaling_bloom_add(bloom, word, strlen(word), i);
0042   }
0043 
0044   int result = bitmap_flush(bloom->bitmap);
0045 
0046   return result;
0047 }
0048 
0049 int main(int argc, char *argv[]) {
0050   printf("** dablooms version: %s\n", dablooms_version());
0051 
0052   if (argc != 3) {
0053     fprintf(stderr, "Usage: %s <bloom_file> <words_file>\n", argv[0]);
0054     return EXIT_FAILURE;
0055   }
0056 
0057   int result = generate_bloom_filter(argv[1], argv[2]);
0058   return result;
0059 }