Home  >  Article  >  Database  >  [Leveldb]源码分析之三 BloomFilter模块的实现

[Leveldb]源码分析之三 BloomFilter模块的实现

WBOY
WBOYOriginal
2016-06-07 17:37:571319browse

应用场景: 由于Leveldb采用的是分层的存储结构,那么当Get一个key的时候最坏情况就是在所有的层级上都查询一遍这个key,这个开销是非常大的,引入BloomFilter之后,利用BloomFilter能够快速判断是否存在的特点可以很快速的知道需不需要在这个Level中进行查

应用场景:

由于Leveldb采用的是分层的存储结构,那么当Get一个key的时候最坏情况就是在所有的层级上都查询一遍这个key,这个开销是非常大的,引入BloomFilter之后,利用BloomFilter能够快速判断“是否存在”的特点可以很快速的知道需不需要在这个Level中进行查询。

构造函数:
explicit BloomFilterPolicy(int bits_per_key)
这里没有默认构造函数,使用时需传入bits_per_key表示每个key的大小

主要流程:
1)初始化:

k_ = static_cast(bits_per_key * 0.69); if (k_ 1) k_ = 1; if (k_ > 30) k_ = 30; ,

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn