FilterPolicy用来过滤不在集合中的key,是用空间换时间的trade 包含下面三个接口:
virtual const char* Name() const = 0; // 返回filter的名字
CreateFilter接口,对key创建filter写入det中
virtual void CreateFilter(const Slice* keys, int n, std::string* dst)const = 0;
KeyMayMatch 接口 匹配过滤key
virtual bool KeyMayMatch(const Slice& key, const Slice& filter)const=0;
对于key的过滤策略采用了Bloom filter. Bloom filter 是由 Howard Bloom 在 1970 年提出的二进制向量数据结构,它具有很好的空间和时间效率,被用来检测一个元素是不是集合中的一个成员,这种检测只会对在集合内的数据错判,而不会对不是集合内的数据进行错判,这样每个检测请求返回有“在集合内(可能错误)”和“不在集合内(绝对不在集合内)”两种情况,可见