filter_policy

// Copyright (c) 2012 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
//
// A database can be configured with a custom FilterPolicy object.
// This object is responsible for creating a small filter from a set
// of keys.  These filters are stored in leveldb and are consulted
// automatically by leveldb to decide whether or not to read some
// information from disk. In many cases, a filter can cut down the
// number of disk seeks form a handful to a single disk seek per
// DB::Get() call.
//
// Most people will want to use the builtin bloom filter support (see
// NewBloomFilterPolicy() below).

#ifndef STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_
#define STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_

#include <string>

namespace leveldb 
{

	class Slice;

	class FilterPolicy 
	{
	public:
		virtual ~FilterPolicy();

		// Return the name of this policy.  Note that if the filter encoding
		// changes in an incompatible way, the name returned by this method
		// must be changed.  Otherwise, old incompatible filters may be
		// passed to methods of this type.
		virtual const charName() const = 0;

		// keys[0,n-1] contains a list of keys (potentially with duplicates)
		// that are ordered according to the user supplied comparator.
		// Append a filter that summarizes keys[0,n-1] to *dst.
		//
		// Warning: do not change the initial contents of *dst.  Instead,
		// append the newly constructed filter to *dst.
		virtual void CreateFilter(const Slice* keys, int n, std::string* dst)
			const = 0;

		// "filter" contains the data appended by a preceding call to
		// CreateFilter() on this class.  This method must return true if
		// the key was in the list of keys passed to CreateFilter().
		// This method may return true or false if the key was not on the
		// list, but it should aim to return false with a high probability.
		virtual bool KeyMayMatch(const Slicekeyconst Slice& filter) const = 0;
	};

	// Return a new filter policy that uses a bloom filter with approximately
	// the specified number of bits per key.  A good value for bits_per_key
	// is 10, which yields a filter with ~ 1% false positive rate.
	//
	// Callers must delete the result after any database that is using the
	// result has been closed.
	//
	// Note: if you are using a custom comparator that ignores some parts
	// of the keys being compared, you must not use NewBloomFilterPolicy()
	// and must provide your own FilterPolicy that also ignores the
	// corresponding parts of the keys.  For example, if the comparator
	// ignores trailing spaces, it would be incorrect to use a
	// FilterPolicy (like NewBloomFilterPolicy) that does not ignore
	// trailing spaces in keys.
	extern const FilterPolicyNewBloomFilterPolicy(int bits_per_key);

}

#endif  // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_
// Copyright (c) 2012 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#include "leveldb/filter_policy.h"

namespace leveldb
{

	FilterPolicy::~FilterPolicy()
	{ 
	}

}  // namespace leveldb

Status TableBuilder::Finish() { Rep* r = rep_; Flush(); assert(!r->closed); r->closed = true; BlockHandle filter_block_handle, metaindex_block_handle, index_block_handle; // Write filter block if (ok() && r->filter_block != nullptr) { WriteRawBlock(r->filter_block->Finish(), kNoCompression, &filter_block_handle); } // Write metaindex block if (ok()) { BlockBuilder meta_index_block(&r->options); if (r->filter_block != nullptr) { // Add mapping from "filter.Name" to location of filter data std::string key = "filter."; key.append(r->options.filter_policy->Name()); std::string handle_encoding; filter_block_handle.EncodeTo(&handle_encoding); meta_index_block.Add(key, handle_encoding); } // TODO(postrelease): Add stats and other meta blocks WriteBlock(&meta_index_block, &metaindex_block_handle); } // Write index block if (ok()) { if (r->pending_index_entry) { r->options.comparator->FindShortSuccessor(&r->last_key); std::string handle_encoding; r->pending_handle.EncodeTo(&handle_encoding); r->index_block.Add(r->last_key, Slice(handle_encoding)); r->pending_index_entry = false; } WriteBlock(&r->index_block, &index_block_handle); } // Write footer if (ok()) { Footer footer; footer.set_metaindex_handle(metaindex_block_handle); footer.set_index_handle(index_block_handle); std::string footer_encoding; footer.EncodeTo(&footer_encoding); r->status = r->file->Append(footer_encoding); if (r->status.ok()) { r->offset += footer_encoding.size(); } } return r->status; }在这段代码里 GenerateFiler()函数被调用了吗
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值