leveldb
Public Member Functions | Private Member Functions | Private Attributes | List of all members
leveldb::anonymous_namespace{cache.cc}::HandleTable Class Reference
Collaboration diagram for leveldb::anonymous_namespace{cache.cc}::HandleTable:
Collaboration graph
[legend]

Public Member Functions

 HandleTable ()
 
 ~HandleTable ()
 
LRUHandleLookup (const Slice &key, uint32_t hash)
 
LRUHandleInsert (LRUHandle *h)
 
LRUHandleRemove (const Slice &key, uint32_t hash)
 

Private Member Functions

LRUHandle ** FindPointer (const Slice &key, uint32_t hash)
 
void Resize ()
 

Private Attributes

uint32_t length_
 
uint32_t elems_
 
LRUHandle ** list_
 

Detailed Description

Definition at line 71 of file cache.cc.

Constructor & Destructor Documentation

§ HandleTable()

leveldb::anonymous_namespace{cache.cc}::HandleTable::HandleTable ( )
inline

§ ~HandleTable()

leveldb::anonymous_namespace{cache.cc}::HandleTable::~HandleTable ( )
inline

Definition at line 74 of file cache.cc.

74 { delete[] list_; }

Member Function Documentation

§ FindPointer()

LRUHandle** leveldb::anonymous_namespace{cache.cc}::HandleTable::FindPointer ( const Slice key,
uint32_t  hash 
)
inlineprivate

Definition at line 116 of file cache.cc.

116  {
117  LRUHandle** ptr = &list_[hash & (length_ - 1)];
118  while (*ptr != NULL &&
119  ((*ptr)->hash != hash || key != (*ptr)->key())) {
120  ptr = &(*ptr)->next_hash;
121  }
122  return ptr;
123  }

§ Insert()

LRUHandle* leveldb::anonymous_namespace{cache.cc}::HandleTable::Insert ( LRUHandle h)
inline

Definition at line 80 of file cache.cc.

80  {
81  LRUHandle** ptr = FindPointer(h->key(), h->hash);
82  LRUHandle* old = *ptr;
83  h->next_hash = (old == NULL ? NULL : old->next_hash);
84  *ptr = h;
85  if (old == NULL) {
86  ++elems_;
87  if (elems_ > length_) {
88  // Since each cache entry is fairly large, we aim for a small
89  // average linked list length (<= 1).
90  Resize();
91  }
92  }
93  return old;
94  }
LRUHandle ** FindPointer(const Slice &key, uint32_t hash)
Definition: cache.cc:116
Here is the call graph for this function:
Here is the caller graph for this function:

§ Lookup()

LRUHandle* leveldb::anonymous_namespace{cache.cc}::HandleTable::Lookup ( const Slice key,
uint32_t  hash 
)
inline

Definition at line 76 of file cache.cc.

76  {
77  return *FindPointer(key, hash);
78  }
LRUHandle ** FindPointer(const Slice &key, uint32_t hash)
Definition: cache.cc:116
Here is the caller graph for this function:

§ Remove()

LRUHandle* leveldb::anonymous_namespace{cache.cc}::HandleTable::Remove ( const Slice key,
uint32_t  hash 
)
inline

Definition at line 96 of file cache.cc.

96  {
97  LRUHandle** ptr = FindPointer(key, hash);
98  LRUHandle* result = *ptr;
99  if (result != NULL) {
100  *ptr = result->next_hash;
101  --elems_;
102  }
103  return result;
104  }
LRUHandle ** FindPointer(const Slice &key, uint32_t hash)
Definition: cache.cc:116
Here is the caller graph for this function:

§ Resize()

void leveldb::anonymous_namespace{cache.cc}::HandleTable::Resize ( )
inlineprivate

Definition at line 125 of file cache.cc.

125  {
126  uint32_t new_length = 4;
127  while (new_length < elems_) {
128  new_length *= 2;
129  }
130  LRUHandle** new_list = new LRUHandle*[new_length];
131  memset(new_list, 0, sizeof(new_list[0]) * new_length);
132  uint32_t count = 0;
133  for (uint32_t i = 0; i < length_; i++) {
134  LRUHandle* h = list_[i];
135  while (h != NULL) {
136  LRUHandle* next = h->next_hash;
137  uint32_t hash = h->hash;
138  LRUHandle** ptr = &new_list[hash & (new_length - 1)];
139  h->next_hash = *ptr;
140  *ptr = h;
141  h = next;
142  count++;
143  }
144  }
145  assert(elems_ == count);
146  delete[] list_;
147  list_ = new_list;
148  length_ = new_length;
149  }

Member Data Documentation

§ elems_

uint32_t leveldb::anonymous_namespace{cache.cc}::HandleTable::elems_
private

Definition at line 110 of file cache.cc.

§ length_

uint32_t leveldb::anonymous_namespace{cache.cc}::HandleTable::length_
private

Definition at line 109 of file cache.cc.

§ list_

LRUHandle** leveldb::anonymous_namespace{cache.cc}::HandleTable::list_
private

Definition at line 111 of file cache.cc.


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