1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/tests/bloom/main.c
Cenk Gündoğan 0a4ea07daa sys: use typedef for struct bloom_t
`bloom_t` is defined as a struct.
`_t` can mislead the user to think of bloom_t
as a typedef (see our coding conventions) instead of a struct.
Thus, I modified `struct bloom_t` to be a *typedefed* struct.

Another solution would be to rename bloom_t to sth. like bloom_s
everywhere and use `struct bloom_s` instead of `bloom_t`.
2014-09-17 19:54:40 +02:00

64 lines
1.4 KiB
C

/*
* Copyright (C) 2013 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief Bloom filter test application
*
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
*
* @}
*/
#include <stdio.h>
#include <string.h>
#include "hashes.h"
#include "bloom.h"
#include "sets.h"
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;
}