mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
tests/bloom_bytes: adjust test to use static buffer for bloom
This commit is contained in:
parent
4b405b9680
commit
13229a6b33
@ -27,7 +27,10 @@
|
||||
#include "hashes.h"
|
||||
#include "bloom.h"
|
||||
#include "random.h"
|
||||
#include "bitfield.h"
|
||||
|
||||
#define BLOOM_BITS (1UL << 12)
|
||||
#define BLOOM_HASHF (8)
|
||||
#define lenB 512
|
||||
#define lenA (10 * 1000)
|
||||
|
||||
@ -38,6 +41,13 @@
|
||||
|
||||
#define BUF_SIZE 50
|
||||
static uint32_t buf[BUF_SIZE];
|
||||
static bloom_t bloom;
|
||||
BITFIELD(bf, BLOOM_BITS);
|
||||
hashfp_t hashes[BLOOM_HASHF] = {
|
||||
(hashfp_t) fnv_hash, (hashfp_t) sax_hash, (hashfp_t) sdbm_hash,
|
||||
(hashfp_t) djb2_hash, (hashfp_t) kr_hash, (hashfp_t) dek_hash,
|
||||
(hashfp_t) rotating_hash, (hashfp_t) one_at_a_time_hash,
|
||||
};
|
||||
|
||||
static void buf_fill(uint32_t *buf, int len)
|
||||
{
|
||||
@ -50,12 +60,11 @@ 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);
|
||||
bloom_init(&bloom, BLOOM_BITS, bf, hashes, BLOOM_HASHF);
|
||||
|
||||
printf("Testing Bloom filter.\n\n");
|
||||
printf("m: %" PRIu32 " k: %" PRIu32 "\n\n", (uint32_t) bloom->m,
|
||||
(uint32_t) bloom->k);
|
||||
printf("m: %" PRIu32 " k: %" PRIu32 "\n\n", (uint32_t) bloom.m,
|
||||
(uint32_t) bloom.k);
|
||||
|
||||
genrand_init(myseed);
|
||||
|
||||
@ -64,7 +73,7 @@ int main(void)
|
||||
for (int i = 0; i < lenB; i++) {
|
||||
buf_fill(buf, BUF_SIZE);
|
||||
buf[0] = MAGIC_B;
|
||||
bloom_add(bloom,
|
||||
bloom_add(&bloom,
|
||||
(uint8_t *) buf,
|
||||
BUF_SIZE * sizeof(uint32_t) / sizeof(uint8_t));
|
||||
}
|
||||
@ -82,7 +91,7 @@ int main(void)
|
||||
buf_fill(buf, BUF_SIZE);
|
||||
buf[0] = MAGIC_A;
|
||||
|
||||
if (bloom_check(bloom,
|
||||
if (bloom_check(&bloom,
|
||||
(uint8_t *) buf,
|
||||
BUF_SIZE * sizeof(uint32_t) / sizeof(uint8_t))) {
|
||||
in++;
|
||||
@ -102,7 +111,7 @@ int main(void)
|
||||
double false_positive_rate = (double) in / (double) lenA;
|
||||
printf("%f false positive rate.\n", false_positive_rate);
|
||||
|
||||
bloom_del(bloom);
|
||||
bloom_del(&bloom);
|
||||
printf("\nAll done!\n");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user