static int contains(Dablooms *self, PyObject *key) { if (!PyString_Check(key)) { return 0; /* return False */ } return scaling_bloom_check(self->filter, PyString_AsString(key), (int)PyString_Size(key)); }
static PyObject *check(Dablooms *self, PyObject *args) { const char *hash; int len; if (!PyArg_ParseTuple(args, "s#", &hash, &len)) { return NULL; } return Py_BuildValue("i", scaling_bloom_check(self->filter, hash, len)); }
static int contains(Dablooms *self, PyObject *key) { const char *hash; int len; if (!PyArg_Parse(key, "s#", &hash, &len)) { return -1; } return scaling_bloom_check(self->filter, hash, len); }
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); }