#include "gp/containers/probabilistic/quotient_filter.hpp"
|
|
#include "test_scaffold.h"
|
|
|
|
#include <random>
|
|
#include <string>
|
|
|
|
typedef std::mt19937_64 cheap_rand;
|
|
typedef std::mt19937_64 cheap_rand_bis;
|
|
|
|
struct qfilter_test : public test_scaffold {
|
|
uint32_t seed;
|
|
|
|
qfilter_test() {
|
|
seed = std::random_device{}();
|
|
name = __FILE__ ":1_seed";
|
|
name += std::to_string(seed);
|
|
}
|
|
|
|
virtual int run() {
|
|
|
|
cheap_rand setter(seed);
|
|
cheap_rand getter(seed);
|
|
|
|
gp::quotient_filter test_filter;
|
|
|
|
for(int a = 0 ; a < 100; a++)
|
|
{
|
|
test_filter.set_hash(setter());
|
|
}
|
|
|
|
bool result = true;
|
|
for(int a = 0 ; a < 100; a++)
|
|
{
|
|
result *= test_filter.test_hash(getter());
|
|
}
|
|
|
|
return !result;
|
|
}
|
|
};
|
|
|
|
append_test dummy_rshyr43(new qfilter_test{});
|
|
|
|
struct qfilter2_test : public test_scaffold {
|
|
uint32_t seedA;
|
|
uint32_t seedB;
|
|
|
|
qfilter2_test() {
|
|
seedA = std::random_device{}();
|
|
seedB = std::random_device{}();
|
|
name = __FILE__ ":2_seedA";
|
|
name += std::to_string(seedA);
|
|
name += "&seedB";
|
|
name += std::to_string(seedB);
|
|
}
|
|
|
|
virtual int run() {
|
|
|
|
cheap_rand setter(seedA);
|
|
cheap_rand deleter(seedA);
|
|
cheap_rand_bis getter(seedB);
|
|
|
|
gp::quotient_filter test_filter;
|
|
|
|
for(int a = 0 ; a < 100000; a++)
|
|
{
|
|
test_filter.set_hash(setter());
|
|
}
|
|
|
|
int interference = 0;
|
|
for(int a = 0 ; a < 100000; a++)
|
|
{
|
|
interference += test_filter.test_hash(getter());
|
|
}
|
|
|
|
for(int a = 0 ; a < 100000; a++)
|
|
{
|
|
test_filter.remove_hash(deleter());
|
|
}
|
|
|
|
return interference > 25;
|
|
}
|
|
};
|
|
|
|
append_test dummy_kegdflu3(new qfilter2_test{});
|
|
|
|
struct qfilter3_test : public test_scaffold {
|
|
uint32_t seedA;
|
|
uint32_t seedB;
|
|
|
|
qfilter3_test() {
|
|
seedA = std::random_device{}();
|
|
seedB = std::random_device{}();
|
|
name = __FILE__ ":3_seedA";
|
|
name += std::to_string(seedA);
|
|
name += "&seedB";
|
|
name += std::to_string(seedB);
|
|
}
|
|
|
|
virtual int run() {
|
|
|
|
cheap_rand setter(seedA);
|
|
cheap_rand deleter(seedA);
|
|
cheap_rand_bis getter(seedB);
|
|
|
|
gp::quotient_filter<uint32_t, 20,12, gp::stepcache_skipstone> test_filter;
|
|
|
|
for(int a = 0 ; a < 100000; a++)
|
|
{
|
|
test_filter.set_hash(setter());
|
|
}
|
|
|
|
int interference = 0;
|
|
for(int a = 0 ; a < 100000; a++)
|
|
{
|
|
interference += test_filter.test_hash(getter());
|
|
}
|
|
|
|
for(int a = 0 ; a < 100000; a++)
|
|
{
|
|
test_filter.remove_hash(deleter());
|
|
}
|
|
|
|
return interference > 25;
|
|
}
|
|
};
|
|
|
|
append_test dummy_kjdflu3(new qfilter3_test{});
|
|
|
|
struct qfilter4_test : public test_scaffold {
|
|
|
|
qfilter4_test() {
|
|
}
|
|
|
|
virtual int run() {
|
|
gp::quotient_filter<> test_filter;
|
|
|
|
for(int a = 0 ; a < 10000; a++)
|
|
{
|
|
test_filter.set_hash(a);
|
|
}
|
|
|
|
for(int a = 0 ; a < 10000; a++)
|
|
{
|
|
test_filter.remove_hash(a);
|
|
}
|
|
|
|
for(int a = 0 ; a < 10000; a++)
|
|
{
|
|
gp_config::assertion(!test_filter.test_hash(a), "everything should have been removed");
|
|
}
|
|
|
|
for(int a = 0 ; a < 10000; a++)
|
|
{
|
|
test_filter.set_hash(a);
|
|
}
|
|
|
|
for(int a = 0 ; a < 10000; a++)
|
|
{
|
|
gp_config::assertion(test_filter.test_hash(a), "everything should have been set");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
append_test dummy_kj54ghu3(new qfilter4_test{});
|
|
|
|
struct qfilter5_test : public test_scaffold {
|
|
|
|
qfilter5_test() {
|
|
}
|
|
|
|
virtual int run() {
|
|
gp::quotient_filter<uint32_t, 16> test_filter;
|
|
|
|
for(int a = 0 ; a < 65536; a++)
|
|
{
|
|
test_filter.set_hash(a);
|
|
}
|
|
|
|
int res = 1;
|
|
|
|
try {
|
|
test_filter.set_hash(123456);
|
|
} catch(gp::runtime_error e) {
|
|
res = 0;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
};
|
|
|
|
append_test dummy_k65421u3(new qfilter5_test{});
|