Skip to content
Snippets Groups Projects
Commit f616a046 authored by Wlad's avatar Wlad
Browse files

feat: add wrapper for chained filter algorithms

parent 0fa2deb1
No related branches found
No related tags found
No related merge requests found
#include <chained/src/Algorithm1.h>
namespace filters::chained {
using ChainedFilterOne = ChainedFilter;
}
\ No newline at end of file
#include <chained/src/Algorithm2.h>
namespace filters::chained {
using ChainedFilterTwo = ChainedFilter;
}
\ No newline at end of file
#pragma once
#include <chained/self-adaptive-hashing/include/CuckooHash.h>
#include <chained/src/Algorithm2.h>
#include <stdio.h>
#include <address/addresser.hpp>
......@@ -11,12 +10,17 @@
#include <simd/vector.hpp>
#include <vector>
#include "algorithm_2.hpp"
namespace filters {
using namespace filters::chained;
template <typename FilterParameter, size_t _k, typename OptimizationParameter>
struct Filter<FilterType::Chained, FilterParameter, _k, OptimizationParameter> {
static constexpr bool supports_add = false;
static constexpr bool supports_add_partition = false;
static constexpr bool supports_remove = false;
using OP = OptimizationParameter;
using FP = FilterParameter;
......@@ -27,71 +31,77 @@ struct Filter<FilterType::Chained, FilterParameter, _k, OptimizationParameter> {
std::unique_ptr<ChainedFilter> filter;
std::unique_ptr<Cuckoo> chained_filter;
size_t n = 1 << 19;
size_t s = 100;
size_t n = 0;
static_assert(OP::partitioning == parameter::Partitioning::Disabled,
"partitioning must be disabled!");
Filter(size_t s, size_t n, size_t n_threads, size_t n_tasks_per_level) : s(s) {}
Filter(size_t s, size_t n, size_t n_threads, size_t n_tasks_per_level) : s(s), n(n) {}
forceinline void init(const T *histogram) {
// size_t item_count = histogram[0];
size_t length = histogram[0];
// TODO: make problem space variable
n = length * s / 100;
auto construct_filter = std::unique_ptr<Cuckoo>(new Cuckoo(n * n, 3));
for (size_t i = 0; i < length * length; i++) {
// auto value = values[i];
if (construct_filter->insert(make_pair(i, i)) == -1) {
return;
}
}
pair<int, int> re = construct_filter->check();
filter = std::unique_ptr<ChainedFilterTwo>(new ChainedFilterTwo(re.first, re.second));
}
forceinline bool contains(const T &value, const size_t = 0) {
if (filter->query(value)) {
int tr = filter->query(value);
if (chained_filter->query_with_pre(value, tr)) {
return true;
}
return chained_filter->query_with_pre(value, false);
return false;
}
forceinline bool add(const T &value, const size_t = 0) {
int re = chained_filter->insert(make_pair(value, value));
filter->insert(value, re);
// reference implementation might fail during insertion
// yet the rehashing is not implemented by original code
// left as is for reference validation
if (chained_filter->insert(make_pair(value, value)) == -1) {
// printf("could not add %d\n", value);
return false;
}
// chained_filter->insert(make_pair(value, value));
filter->insert(value, chained_filter->getpos(value));
return true;
}
bool construct(T *values, size_t length) {
size_t n = length * s / 100;
auto construct_filter = std::unique_ptr<Cuckoo>(new Cuckoo(n));
for (size_t i = 0; i < length; i++) {
auto value = values[i];
if (construct_filter->insert(make_pair(value, value)) == -1) {
return false;
}
forceinline bool remove(const T &value) {
if (contains(value)) {
filter->change(value, false);
}
pair<int, int> re = construct_filter->check();
printf("could not remove %d \n", value);
return false;
}
chained_filter = std::unique_ptr<Cuckoo>(new Cuckoo(n));
filter = std::unique_ptr<ChainedFilter>(new ChainedFilter(re.first, re.second));
for (size_t i = 0; i < length; i++) {
auto value = values[i];
chained_filter->insert(make_pair(value, value));
}
for (size_t i = 0; i < length; i++) {
auto value = values[i];
int re = chained_filter->getpos(value);
filter->insert(value, re);
}
size_t last_value = 0;
bool construct(T *values, size_t length) {
T histogram = length;
for (int tt = 0; tt <= 10; tt++) {
size_t sum = 0;
for (size_t i = 0; i < length; i++) {
int tr = filter->query(i);
if (chained_filter->query_with_pre(i, tr)) {
sum++;
filter->change(i, !tr);
}
}
// create stage 1 filter, ChainedFilter instance and setup n
init(&histogram);
if (last_value == sum) {
printf("stabalized after %d iterations at %d mistakes", tt, sum);
break;
}
chained_filter = std::unique_ptr<Cuckoo>(new Cuckoo(n, 3));
last_value = sum;
for (size_t i = 0; i < n; i++) {
T value = values[i];
if (chained_filter->insert(make_pair(value, value)) == -1) {
return false;
}
}
for (size_t i = 0; i < n; i++) {
T value = values[i];
int pos = chained_filter->getpos(value);
filter->insert(value, pos);
}
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment