示例#1
0
int test_scaling_accuracy(const char *bloom_file, const char *words_file)
{
    FILE *fp;
    char word[256];
    scaling_bloom_t *bloom;
    int i;
    struct stats results = { 0 };
    
    printf("\n* test scaling accuracy\n");
    
    if ((fp = fopen(bloom_file, "r"))) {
        fclose(fp);
        remove(bloom_file);
    }
    
    if (!(bloom = new_scaling_bloom(CAPACITY, ERROR_RATE, bloom_file))) {
        fprintf(stderr, "ERROR: Could not create bloom filter\n");
        return TEST_FAIL;
    }
    
    if (!(fp = fopen(words_file, "r"))) {
        fprintf(stderr, "ERROR: Could not open words file\n");
        return TEST_FAIL;
    }
    
    for (i = 0; fgets(word, sizeof(word), fp); i++) {
        if (i % 2 == 0) {
            chomp_line(word);
            scaling_bloom_add(bloom, word, strlen(word), i);
        }
    }
    
    fseek(fp, 0, SEEK_SET);
    for (i = 0; fgets(word, sizeof(word), fp); i++) {
        if (i % 2 == 1) {
            chomp_line(word);
            bloom_score(scaling_bloom_check(bloom, word, strlen(word)), 0, &results, word);
        }
    }
    
    fclose(fp);
    
    printf("Elements added:   %6d" "\n"
           "Elements checked: %6d" "\n"
           "Total size: %d KiB"  "\n\n",
           (i + 1) / 2, i / 2,
           (int) bloom->num_bytes / 1024);
           
    free_scaling_bloom(bloom);
    
    return print_results(&results);
}
示例#2
0
static int Dablooms_init(Dablooms *self, PyObject *args, PyObject *kwds)
{
    double error_rate;
    const char *filepath;
    unsigned int capacity;
    static char *kwlist[] = {"capacity", "error_rate", "filepath", NULL};
    
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "|ids", kwlist,
                                      &capacity, &error_rate, &filepath)) {
        return -1;
    }
    
    self->filter = new_scaling_bloom(capacity, error_rate, filepath);
    
    return 0;
}