Skip to content

A little confused about the bloom filter #1257

Open
@mumupika

Description

@mumupika

In the code of bloom.cc, I found that the following code to create bloom filter:

    // Compute bloom filter size (in both bits and bytes)
    size_t bits = n * bits_per_key_;

    // For small n, we can see a very high false positive rate.  Fix it
    // by enforcing a minimum bloom filter length.
    if (bits < 64) bits = 64;

    size_t bytes = (bits + 7) / 8;
    bits = bytes * 8;
    const size_t init_size = dst->size();
    dst->resize(init_size + bytes, 0);
    dst->push_back(static_cast<char>(k_));  // Remember # of probes in filter

This means that the bloom filter should be at least has a size of 9.
But in the later code in bool KeyMayMatch(const Slice& key, const Slice& bloom_filter) const override, I found the following code:

const size_t len = bloom_filter.size();
if (len < 2) return false;

I guess that these are used to test the completeness of the bloom filter. But I wonder that should the length be 9? Or maybe I mistakenly understood them?

I am eager for an answer! And I am appreciate if you can help me! Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions