END_TEST START_TEST(test_union) { BloomFilter *bf1 = BloomFilterCreate(); BloomFilter *bf2 = BloomFilterCreate(); int num_keys = 25000; int *keys = palloc(sizeof(int) * num_keys * 2); int i; for (i = 0; i < num_keys; i++) { int k1 = rand(); int k2 = rand(); keys[i] = k1; keys[num_keys + i] = k2; BloomFilterAdd(bf1, &k1, sizeof(int)); BloomFilterAdd(bf2, &k2, sizeof(int)); } bf1 = BloomFilterUnion(bf1, bf2); for (i = 0; i < num_keys * 2; i++) ck_assert(BloomFilterContains(bf1, &keys[i], sizeof(int))); }
Datum bloom_add(PG_FUNCTION_ARGS) { BloomFilter *bloom; if (PG_ARGISNULL(0)) bloom = BloomFilterCreate(); else bloom = (BloomFilter *) PG_GETARG_VARLENA_P(0); fcinfo->flinfo->fn_extra = lookup_type_cache(get_fn_expr_argtype(fcinfo->flinfo, 1), 0); bloom = bloom_add_datum(fcinfo, bloom, PG_GETARG_DATUM(1)); PG_RETURN_POINTER(bloom); }
static BloomFilter * bloom_startup(FunctionCallInfo fcinfo, float8 p, uint64_t n) { BloomFilter *bloom; Oid type = AggGetInitialArgType(fcinfo); fcinfo->flinfo->fn_extra = lookup_type_cache(type, 0); if (p && n) { bloom = bloom_create(p, n); } else bloom = BloomFilterCreate(); return bloom; }
Datum bloom_empty(PG_FUNCTION_ARGS) { BloomFilter *bloom = BloomFilterCreate(); PG_RETURN_POINTER(bloom); }