|
@@ -28,14 +28,20 @@ namespace nanxing_extend
|
|
|
//move-only
|
|
|
FilterPolicy(){};
|
|
|
FilterPolicy(FilterPolicy&&){}
|
|
|
- virtual void policy_print(){producter->policy_print();} //输出对应的计算公式
|
|
|
- virtual void parameter_print(){producter->parameter_print();} //输出过滤器的参数
|
|
|
- virtual void insert(K key)noexcept{};
|
|
|
+ virtual void policy_print(){} //输出对应的计算公式
|
|
|
+ virtual void parameter_print(){} //输出过滤器的参数
|
|
|
+ virtual void insert(K key)noexcept{}; //当向数据库插入数据后对过滤器进行调整
|
|
|
+ [[nodiscard]]virtual bool check(K key)noexcept{};
|
|
|
//两个工厂函数用于生成不同的过滤器
|
|
|
FilterPolicy* creat_Bloomfilter(int N,int P);
|
|
|
FilterPolicy* creat_Cuckoofilter();
|
|
|
- virtual void init_filter(){producter->init_filter();} //初始化过滤器
|
|
|
- virtual ~FilterPolicy(){};
|
|
|
+ virtual void init_filter(){} //初始化过滤器
|
|
|
+ virtual ~FilterPolicy(){
|
|
|
+ if(producter!=nullptr)
|
|
|
+ {
|
|
|
+ delete producter;
|
|
|
+ }
|
|
|
+ };
|
|
|
};
|
|
|
|
|
|
//bloomfilter
|
|
@@ -125,8 +131,28 @@ namespace nanxing_extend
|
|
|
int tmp=this->hash_function(i,key);
|
|
|
int filter_u=static_cast<int>(tmp/8);
|
|
|
int move=tmp%8;
|
|
|
- this->bitarray[filter_u]||('1'<<(7-move));
|
|
|
+ this->bitarray[filter_u]=this->bitarray[filter_u]|('1'<<(7-move));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [[nodiscard]]bool check(K key)noexcept override
|
|
|
+ {
|
|
|
+ if(this->parameter.k==0)
|
|
|
+ {
|
|
|
+ std::cerr<<"the filter never init,and the filter is useless."<<std::endl;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for(int i=0;i<this->parameter.k;i++)
|
|
|
+ {
|
|
|
+ int tmp=this->hash_function(i,key);
|
|
|
+ int filter_u=static_cast<int>(tmp/8);
|
|
|
+ int move=tmp%8;
|
|
|
+ if((this->bitarray[filter_u]&('1'<<(7-move)))==0) //若对应位为0
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
virtual ~bloomfilter()
|