leveldb
Public Member Functions | Private Attributes | List of all members
leveldb::FilterBlockReader Class Reference

#include <filter_block.h>

Collaboration diagram for leveldb::FilterBlockReader:
Collaboration graph
[legend]

Public Member Functions

 FilterBlockReader (const FilterPolicy *policy, const Slice &contents)
 
bool KeyMayMatch (uint64_t block_offset, const Slice &key)
 

Private Attributes

const FilterPolicypolicy_
 
const char * data_
 
const char * offset_
 
size_t num_
 
size_t base_lg_
 

Detailed Description

Definition at line 52 of file filter_block.h.

Constructor & Destructor Documentation

§ FilterBlockReader()

leveldb::FilterBlockReader::FilterBlockReader ( const FilterPolicy policy,
const Slice contents 
)

Definition at line 78 of file filter_block.cc.

80  : policy_(policy),
81  data_(NULL),
82  offset_(NULL),
83  num_(0),
84  base_lg_(0) {
85  size_t n = contents.size();
86  if (n < 5) return; // 1 byte for base_lg_ and 4 for start of offset array
87  base_lg_ = contents[n-1];
88  uint32_t last_word = DecodeFixed32(contents.data() + n - 5);
89  if (last_word > n - 5) return;
90  data_ = contents.data();
91  offset_ = data_ + last_word;
92  num_ = (n - 5 - last_word) / 4;
93 }
uint32_t DecodeFixed32(const char *ptr)
Definition: coding.h:58
const FilterPolicy * policy_
Definition: filter_block.h:59
Here is the call graph for this function:

Member Function Documentation

§ KeyMayMatch()

bool leveldb::FilterBlockReader::KeyMayMatch ( uint64_t  block_offset,
const Slice key 
)

Definition at line 95 of file filter_block.cc.

95  {
96  uint64_t index = block_offset >> base_lg_;
97  if (index < num_) {
98  uint32_t start = DecodeFixed32(offset_ + index*4);
99  uint32_t limit = DecodeFixed32(offset_ + index*4 + 4);
100  if (start <= limit && limit <= static_cast<size_t>(offset_ - data_)) {
101  Slice filter = Slice(data_ + start, limit - start);
102  return policy_->KeyMayMatch(key, filter);
103  } else if (start == limit) {
104  // Empty filters do not match any keys
105  return false;
106  }
107  }
108  return true; // Errors are treated as potential matches
109 }
virtual bool KeyMayMatch(const Slice &key, const Slice &filter) const =0
uint32_t DecodeFixed32(const char *ptr)
Definition: coding.h:58
const FilterPolicy * policy_
Definition: filter_block.h:59
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

§ base_lg_

size_t leveldb::FilterBlockReader::base_lg_
private

Definition at line 63 of file filter_block.h.

§ data_

const char* leveldb::FilterBlockReader::data_
private

Definition at line 60 of file filter_block.h.

§ num_

size_t leveldb::FilterBlockReader::num_
private

Definition at line 62 of file filter_block.h.

§ offset_

const char* leveldb::FilterBlockReader::offset_
private

Definition at line 61 of file filter_block.h.

§ policy_

const FilterPolicy* leveldb::FilterBlockReader::policy_
private

Definition at line 59 of file filter_block.h.


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