Exemple #1
0
/**
 * Gets the current byte size of the filter
 * @note Thread safe.
 * @arg filter The filter
 * @return The total byte size of the filter
 */
uint64_t bloomf_byte_size(bloom_filter *filter) {
    if (filter->sbf) {
        return sbf_total_byte_size((bloom_sbf*)filter->sbf);
    } else {
        return filter->filter_config.bytes;
    }
}
Exemple #2
0
END_TEST

START_TEST(sbf_add_filter_2)
{
    bloom_sbf_params params = SBF_DEFAULT_PARAMS;
    params.initial_capacity = 1e3;
    params.fp_probability = 1e-5;
    bloom_sbf sbf;
    int res = sbf_from_filters(&params, NULL, NULL, 0, NULL, &sbf);
    fail_unless(res == 0);

    // Check all the keys get added
    char buf[100];
    for (int i=0;i<10000;i++) {
        snprintf((char*)&buf, 100, "foobar%d", i);
        res = sbf_add(&sbf, (char*)&buf);
        fail_unless(res == 1);
    }

    fail_unless(sbf_size(&sbf) == 10000);
    fail_unless(sbf.num_filters == 3);
    fail_unless(sbf_total_capacity(&sbf) == 21*1e3);

    // Check all the keys exist
    for (int i=0;i<10000;i++) {
        snprintf((char*)&buf, 100, "foobar%d", i);
        res = sbf_contains(&sbf, (char*)&buf);
        fail_unless(res == 1);
    }

    // Byte size should be greater than a static filter of the same config
    bloom_filter_params config_params = {0, 0, 21e3, 1e-4};
    bf_params_for_capacity(&config_params);
    uint64_t total_size = sbf_total_byte_size(&sbf);
    fail_unless(total_size > config_params.bytes);
    fail_unless(total_size < 2 * config_params.bytes);
}