示例#1
0
void test_bloom_insert()
{
	int size = 8;
	int hashes = 4;
	char string[] = "test";
	bloom_filter_t filter;

	filter = bloom_new(size, hashes);
	bloom_insert(&filter, string, 4);
	ok(
		filter.num_members == 1,
		"bloom_insert ok."
	);
}
示例#2
0
void test_bloom_query()
{
	int size = 8;
	int hashes = 4;
	char string[] = "test";
	bloom_filter_t filter;

	filter = bloom_new(size, hashes);
	bloom_insert(&filter, string, 4);
	int res = bloom_query(&filter, string, 4);

	ok(
		res == 1,
		"bloom_query ok."
	) |
	diag(
		"Expected %d got %d.",
		1,
		res
	);
}
示例#3
0
文件: bloom.c 项目: aido/picocoin
static void runtest (void)
{
	unsigned char md1[SHA256_DIGEST_LENGTH];
	unsigned char md2[SHA256_DIGEST_LENGTH];

	sha256_Raw((unsigned char *)data1, strlen(data1), md1);
	sha256_Raw((unsigned char *)data2, strlen(data2), md2);

	struct bloom bloom;

	assert(bloom_init(&bloom, 1000, 0.001) == true);

	bloom_insert(&bloom, md1, sizeof(md1));

	assert(bloom_contains(&bloom, md1, sizeof(md1)) == true);
	assert(bloom_contains(&bloom, md2, sizeof(md2)) == false);

	cstring *ser = cstr_new_sz(1024);
	ser_bloom(ser, &bloom);

	struct bloom bloom2;
	__bloom_init(&bloom2);

	struct const_buffer buf = { ser->str, ser->len };

	assert(deser_bloom(&bloom2, &buf) == true);

	assert(bloom.nHashFuncs == bloom2.nHashFuncs);
	assert(bloom.vData->len == bloom2.vData->len);
	assert(memcmp(bloom.vData->str, bloom2.vData->str, bloom2.vData->len) == 0);

	assert(bloom_contains(&bloom2, md1, sizeof(md1)) == true);
	assert(bloom_contains(&bloom2, md2, sizeof(md2)) == false);

	bloom_free(&bloom2);

	bloom_free(&bloom);

	cstr_free(ser, true);
}