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

#include <block.h>

Classes

class  Iter
 

Public Member Functions

 Block (const BlockContents &contents)
 
 ~Block ()
 
size_t size () const
 
IteratorNewIterator (const Comparator *comparator)
 

Private Member Functions

uint32_t NumRestarts () const
 
 Block (const Block &)
 
void operator= (const Block &)
 

Private Attributes

const char * data_
 
size_t size_
 
uint32_t restart_offset_
 
bool owned_
 

Detailed Description

Definition at line 17 of file block.h.

Constructor & Destructor Documentation

§ Block() [1/2]

leveldb::Block::Block ( const BlockContents contents)
explicit

Definition at line 23 of file block.cc.

24  : data_(contents.data.data()),
25  size_(contents.data.size()),
26  owned_(contents.heap_allocated) {
27  if (size_ < sizeof(uint32_t)) {
28  size_ = 0; // Error marker
29  } else {
30  size_t max_restarts_allowed = (size_-sizeof(uint32_t)) / sizeof(uint32_t);
31  if (NumRestarts() > max_restarts_allowed) {
32  // The size is too small for NumRestarts()
33  size_ = 0;
34  } else {
35  restart_offset_ = size_ - (1 + NumRestarts()) * sizeof(uint32_t);
36  }
37  }
38 }
size_t size_
Definition: block.h:31
uint32_t NumRestarts() const
Definition: block.cc:18
uint32_t restart_offset_
Definition: block.h:32
const char * data_
Definition: block.h:30
bool owned_
Definition: block.h:33
Here is the call graph for this function:

§ ~Block()

leveldb::Block::~Block ( )

Definition at line 40 of file block.cc.

40  {
41  if (owned_) {
42  delete[] data_;
43  }
44 }
const char * data_
Definition: block.h:30
bool owned_
Definition: block.h:33

§ Block() [2/2]

leveldb::Block::Block ( const Block )
private

Member Function Documentation

§ NewIterator()

Iterator * leveldb::Block::NewIterator ( const Comparator comparator)

Definition at line 256 of file block.cc.

256  {
257  if (size_ < sizeof(uint32_t)) {
258  return NewErrorIterator(Status::Corruption("bad block contents"));
259  }
260  const uint32_t num_restarts = NumRestarts();
261  if (num_restarts == 0) {
262  return NewEmptyIterator();
263  } else {
264  return new Iter(cmp, data_, restart_offset_, num_restarts);
265  }
266 }
size_t size_
Definition: block.h:31
uint32_t NumRestarts() const
Definition: block.cc:18
static Status Corruption(const Slice &msg, const Slice &msg2=Slice())
Definition: status.h:38
Iterator * NewErrorIterator(const Status &status)
Definition: iterator.cc:63
uint32_t restart_offset_
Definition: block.h:32
Iterator * NewEmptyIterator()
Definition: iterator.cc:59
const char * data_
Definition: block.h:30
Here is the call graph for this function:
Here is the caller graph for this function:

§ NumRestarts()

uint32_t leveldb::Block::NumRestarts ( ) const
inlineprivate

Definition at line 18 of file block.cc.

18  {
19  assert(size_ >= sizeof(uint32_t));
20  return DecodeFixed32(data_ + size_ - sizeof(uint32_t));
21 }
size_t size_
Definition: block.h:31
uint32_t DecodeFixed32(const char *ptr)
Definition: coding.h:58
const char * data_
Definition: block.h:30
Here is the call graph for this function:
Here is the caller graph for this function:

§ operator=()

void leveldb::Block::operator= ( const Block )
private

§ size()

size_t leveldb::Block::size ( ) const
inline

Definition at line 24 of file block.h.

24 { return size_; }
size_t size_
Definition: block.h:31
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

§ data_

const char* leveldb::Block::data_
private

Definition at line 30 of file block.h.

§ owned_

bool leveldb::Block::owned_
private

Definition at line 33 of file block.h.

§ restart_offset_

uint32_t leveldb::Block::restart_offset_
private

Definition at line 32 of file block.h.

§ size_

size_t leveldb::Block::size_
private

Definition at line 31 of file block.h.


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