Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2012 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.4//5// A filter block is stored near the end of a Table file. It contains6// filters (e.g., bloom filters) for all data blocks in the table combined7// into a single filter block.9#ifndef STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_10#define STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_12#include <stddef.h>13#include <stdint.h>15#include <string>16#include <vector>18#include "leveldb/slice.h"19#include "util/hash.h"21namespace leveldb {23class FilterPolicy;25// A FilterBlockBuilder is used to construct all of the filters for a26// particular Table. It generates a single string which is stored as27// a special block in the Table.28//29// The sequence of calls to FilterBlockBuilder must match the regexp:30// (StartBlock AddKey*)* Finish31class FilterBlockBuilder {32public:33explicit FilterBlockBuilder(const FilterPolicy*);35FilterBlockBuilder(const FilterBlockBuilder&) = delete;36FilterBlockBuilder& operator=(const FilterBlockBuilder&) = delete;38void StartBlock(uint64_t block_offset);39void AddKey(const Slice& key);40Slice Finish();42private:43void GenerateFilter();45const FilterPolicy* policy_;46std::string keys_; // Flattened key contents47std::vector<size_t> start_; // Starting index in keys_ of each key48std::string result_; // Filter data computed so far49std::vector<Slice> tmp_keys_; // policy_->CreateFilter() argument50std::vector<uint32_t> filter_offsets_;51};53class FilterBlockReader {54public:55// REQUIRES: "contents" and *policy must stay live while *this is live.56FilterBlockReader(const FilterPolicy* policy, const Slice& contents);57bool KeyMayMatch(uint64_t block_offset, const Slice& key);59private:60const FilterPolicy* policy_;61const char* data_; // Pointer to filter data (at block-start)62const char* offset_; // Pointer to beginning of offset array (at block-end)63size_t num_; // Number of entries in offset array64size_t base_lg_; // Encoding parameter (see kFilterBaseLg in .cc file)65};67} // namespace leveldb69#endif // STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.