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); }
static PyObject *add(Dablooms *self, PyObject *args, PyObject *kwds) { const char *hash; int len; unsigned long long id; static char *kwlist[] = {"hash", "id", NULL}; if (! PyArg_ParseTupleAndKeywords(args, kwds, "|s#K", kwlist, &hash, &len, &id)) { return NULL; } return Py_BuildValue("i", scaling_bloom_add(self->filter, hash, len, id)); }