leveldb
Public Member Functions | Private Attributes | List of all members
leveldb::BloomTest Class Reference
Collaboration diagram for leveldb::BloomTest:
Collaboration graph
[legend]

Public Member Functions

 BloomTest ()
 
 ~BloomTest ()
 
void Reset ()
 
void Add (const Slice &s)
 
void Build ()
 
size_t FilterSize () const
 
void DumpFilter ()
 
bool Matches (const Slice &s)
 
double FalsePositiveRate ()
 

Private Attributes

const FilterPolicypolicy_
 
std::string filter_
 
std::vector< std::string > keys_
 

Detailed Description

Definition at line 21 of file bloom_test.cc.

Constructor & Destructor Documentation

§ BloomTest()

leveldb::BloomTest::BloomTest ( )
inline

Definition at line 28 of file bloom_test.cc.

const FilterPolicy * NewBloomFilterPolicy(int bits_per_key)
Definition: bloom.cc:91
const FilterPolicy * policy_
Definition: bloom_test.cc:23

§ ~BloomTest()

leveldb::BloomTest::~BloomTest ( )
inline

Definition at line 30 of file bloom_test.cc.

30  {
31  delete policy_;
32  }
const FilterPolicy * policy_
Definition: bloom_test.cc:23

Member Function Documentation

§ Add()

void leveldb::BloomTest::Add ( const Slice s)
inline

Definition at line 39 of file bloom_test.cc.

39  {
40  keys_.push_back(s.ToString());
41  }
std::vector< std::string > keys_
Definition: bloom_test.cc:25
Here is the call graph for this function:
Here is the caller graph for this function:

§ Build()

void leveldb::BloomTest::Build ( )
inline

Definition at line 43 of file bloom_test.cc.

43  {
44  std::vector<Slice> key_slices;
45  for (size_t i = 0; i < keys_.size(); i++) {
46  key_slices.push_back(Slice(keys_[i]));
47  }
48  filter_.clear();
49  policy_->CreateFilter(&key_slices[0], static_cast<int>(key_slices.size()),
50  &filter_);
51  keys_.clear();
52  if (kVerbose >= 2) DumpFilter();
53  }
std::string filter_
Definition: bloom_test.cc:24
std::vector< std::string > keys_
Definition: bloom_test.cc:25
virtual void CreateFilter(const Slice *keys, int n, std::string *dst) const =0
const FilterPolicy * policy_
Definition: bloom_test.cc:23
static const int kVerbose
Definition: bloom_test.cc:14
Here is the call graph for this function:
Here is the caller graph for this function:

§ DumpFilter()

void leveldb::BloomTest::DumpFilter ( )
inline

Definition at line 59 of file bloom_test.cc.

59  {
60  fprintf(stderr, "F(");
61  for (size_t i = 0; i+1 < filter_.size(); i++) {
62  const unsigned int c = static_cast<unsigned int>(filter_[i]);
63  for (int j = 0; j < 8; j++) {
64  fprintf(stderr, "%c", (c & (1 <<j)) ? '1' : '.');
65  }
66  }
67  fprintf(stderr, ")\n");
68  }
std::string filter_
Definition: bloom_test.cc:24
Here is the caller graph for this function:

§ FalsePositiveRate()

double leveldb::BloomTest::FalsePositiveRate ( )
inline

Definition at line 77 of file bloom_test.cc.

77  {
78  char buffer[sizeof(int)];
79  int result = 0;
80  for (int i = 0; i < 10000; i++) {
81  if (Matches(Key(i + 1000000000, buffer))) {
82  result++;
83  }
84  }
85  return result / 10000.0;
86  }
uint64_t Key
bool Matches(const Slice &s)
Definition: bloom_test.cc:70
Here is the call graph for this function:
Here is the caller graph for this function:

§ FilterSize()

size_t leveldb::BloomTest::FilterSize ( ) const
inline

Definition at line 55 of file bloom_test.cc.

55  {
56  return filter_.size();
57  }
std::string filter_
Definition: bloom_test.cc:24
Here is the caller graph for this function:

§ Matches()

bool leveldb::BloomTest::Matches ( const Slice s)
inline

Definition at line 70 of file bloom_test.cc.

70  {
71  if (!keys_.empty()) {
72  Build();
73  }
74  return policy_->KeyMayMatch(s, filter_);
75  }
virtual bool KeyMayMatch(const Slice &key, const Slice &filter) const =0
std::string filter_
Definition: bloom_test.cc:24
std::vector< std::string > keys_
Definition: bloom_test.cc:25
const FilterPolicy * policy_
Definition: bloom_test.cc:23
Here is the call graph for this function:
Here is the caller graph for this function:

§ Reset()

void leveldb::BloomTest::Reset ( )
inline

Definition at line 34 of file bloom_test.cc.

34  {
35  keys_.clear();
36  filter_.clear();
37  }
std::string filter_
Definition: bloom_test.cc:24
std::vector< std::string > keys_
Definition: bloom_test.cc:25
Here is the caller graph for this function:

Member Data Documentation

§ filter_

std::string leveldb::BloomTest::filter_
private

Definition at line 24 of file bloom_test.cc.

§ keys_

std::vector<std::string> leveldb::BloomTest::keys_
private

Definition at line 25 of file bloom_test.cc.

§ policy_

const FilterPolicy* leveldb::BloomTest::policy_
private

Definition at line 23 of file bloom_test.cc.


The documentation for this class was generated from the following file: