Beispiel #1
0
static BloomFilter *
bloom_create(float8 p, uint64_t n)
{
	if (p <= 0 || p >= 1)
		ereport(ERROR,
				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
				errmsg("p must be in [0, 1]")));
	if (n < 1)
		ereport(ERROR,
				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
				errmsg("n must be non-zero")));

	return BloomFilterCreateWithPAndN(p, n);
}
Beispiel #2
0
END_TEST

START_TEST(test_false_positives)
{
	float p = 0.01;
	int n = 10000;
	BloomFilter *bf = BloomFilterCreateWithPAndN(p, n);
	float fp = 0;
	int i;

	for (i = 0; i < n; i++)
		BloomFilterAdd(bf, &i, sizeof(int));

	for (i = 0; i < n; i++)
	{
		int r = rand();
		if (BloomFilterContains(bf, &r, sizeof(int)))
			fp++;
	}

	ck_assert_int_le(fp / n, p);
}