int main(void) { bloom_t *bloom = bloom_new(1 << 7, 6, fnv_hash, sax_hash, sdbm_hash, djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash); printf("Testing Bloom filter.\n\n"); printf("m: %zd\nk: %zd\n\n", bloom->m, bloom->k); for (int i = 0; i < lenB; i++) { bloom_add(bloom, (const uint8_t *) B[i], strlen(B[i])); printf("Added \"%s\"\n", B[i]); } int in = 0; int not_in = 0; for (int i = 0; i < lenA; i++) { if (bloom_check(bloom, (const uint8_t *) A[i], strlen(A[i]))) { in++; } else { not_in++; } } printf("\n"); printf("%d elements probably in the filter.\n", in); printf("%d elements not in the filter.\n", not_in); double false_positive_rate = (double) in / (double) lenA; printf("%f false positive rate.\n", false_positive_rate); bloom_del(bloom); printf("\nAll done!\n"); return 0; }
int main(void) { xtimer_init(); bloom_t *bloom = bloom_new(1 << 12, 8, fnv_hash, sax_hash, sdbm_hash, djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash); printf("Testing Bloom filter.\n\n"); printf("m: %" PRIu32 " k: %" PRIu32 "\n\n", (uint32_t) bloom->m, (uint32_t) bloom->k); genrand_init(myseed); unsigned long t1 = xtimer_now(); for (int i = 0; i < lenB; i++) { buf_fill(buf, BUF_SIZE); buf[0] = MAGIC_B; bloom_add(bloom, (uint8_t *) buf, BUF_SIZE * sizeof(uint32_t) / sizeof(uint8_t)); } unsigned long t2 = xtimer_now(); printf("adding %d elements took %" PRIu32 "ms\n", lenB, (uint32_t) (t2 - t1) / 1000); int in = 0; int not_in = 0; unsigned long t3 = xtimer_now(); for (int i = 0; i < lenA; i++) { buf_fill(buf, BUF_SIZE); buf[0] = MAGIC_A; if (bloom_check(bloom, (uint8_t *) buf, BUF_SIZE * sizeof(uint32_t) / sizeof(uint8_t))) { in++; } else { not_in++; } } unsigned long t4 = xtimer_now(); printf("checking %d elements took %" PRIu32 "ms\n", lenA, (uint32_t) (t4 - t3) / 1000); printf("\n"); printf("%d elements probably in the filter.\n", in); printf("%d elements not in the filter.\n", not_in); double false_positive_rate = (double) in / (double) lenA; printf("%f false positive rate.\n", false_positive_rate); bloom_del(bloom); printf("\nAll done!\n"); return 0; }
int main(void) { plan_tests(6); setvbuf(stdout, 0, _IOLBF, 0); BLOOM *bp = bloom_create(12, 16, 2); ok(bp, "created"); int rc = bloom_chk(bp, "AB"); ok(rc == 0, "Check 'AB' not in empty table: %d", rc); printf("# Add AB\n"); bloom_add(bp, "AB"); rc = bloom_chk(bp, "AB"); ok(rc != 0, "Check 'AB' after add: %d", rc); printf("# Add AC\n"); bloom_add(bp, "AC"); rc = bloom_chk(bp, "!@"); ok(rc != 0, "Check '!@' without add: %d (false positive)", rc); printf("# Before adding CA...DZ\n"); bloom_dump(bp, stdout); int antestat = bloom_stat(bp), anteover = bloom_over(bp); char hash[] = "__"; for (hash[1] = 'A'; hash[1] <= 'D'; ++hash[1]) for (hash[0] = 'C'; hash[0] <= 'Z'; ++hash[0]) bloom_add(bp, hash); printf("# After adding CA...DZ:\n"); bloom_dump(bp, stdout); for (hash[1] = 'A'; hash[1] <= 'D'; ++hash[1]) for (hash[0] = 'C'; hash[0] <= 'Z'; ++hash[0]) bloom_del(bp, hash); printf("# After deleting CA...DZ:\n"); bloom_dump(bp, stdout); int poststat = bloom_stat(bp), postover = bloom_over(bp); ok(poststat == antestat, "stat %d -> %d", antestat, poststat); ok(postover == anteover, "over %d -> %d", anteover, postover); bloom_destroy(bp); return exit_status(); }
static void tear_down_bloom(void) { bloom_del(&bloom); }