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

Public Member Functions

 ShardedLRUCache (size_t capacity)
 
virtual ~ShardedLRUCache ()
 
virtual HandleInsert (const Slice &key, void *value, size_t charge, void(*deleter)(const Slice &key, void *value))
 
virtual HandleLookup (const Slice &key)
 
virtual void Release (Handle *handle)
 
virtual void Erase (const Slice &key)
 
virtual void * Value (Handle *handle)
 
virtual uint64_t NewId ()
 
virtual void Prune ()
 
virtual size_t TotalCharge () const
 
- Public Member Functions inherited from leveldb::Cache
 Cache ()
 
virtual ~Cache ()
 

Static Private Member Functions

static uint32_t HashSlice (const Slice &s)
 
static uint32_t Shard (uint32_t hash)
 

Private Attributes

LRUCache shard_ [kNumShards]
 
port::Mutex id_mutex_
 
uint64_t last_id_
 

Detailed Description

Definition at line 338 of file cache.cc.

Constructor & Destructor Documentation

§ ShardedLRUCache()

leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::ShardedLRUCache ( size_t  capacity)
inlineexplicit

Definition at line 353 of file cache.cc.

354  : last_id_(0) {
355  const size_t per_shard = (capacity + (kNumShards - 1)) / kNumShards;
356  for (int s = 0; s < kNumShards; s++) {
357  shard_[s].SetCapacity(per_shard);
358  }
359  }
Here is the call graph for this function:

§ ~ShardedLRUCache()

virtual leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::~ShardedLRUCache ( )
inlinevirtual

Definition at line 360 of file cache.cc.

360 { }

Member Function Documentation

§ Erase()

virtual void leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::Erase ( const Slice key)
inlinevirtual

Implements leveldb::Cache.

Definition at line 374 of file cache.cc.

374  {
375  const uint32_t hash = HashSlice(key);
376  shard_[Shard(hash)].Erase(key, hash);
377  }
static uint32_t HashSlice(const Slice &s)
Definition: cache.cc:344
void Erase(const Slice &key, uint32_t hash)
Definition: cache.cc:318
Here is the call graph for this function:

§ HashSlice()

static uint32_t leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::HashSlice ( const Slice s)
inlinestaticprivate

Definition at line 344 of file cache.cc.

344  {
345  return Hash(s.data(), s.size(), 0);
346  }
uint32_t Hash(const char *data, size_t n, uint32_t seed)
Definition: hash.cc:18
Here is the call graph for this function:

§ Insert()

virtual Handle* leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::Insert ( const Slice key,
void *  value,
size_t  charge,
void(*)(const Slice &key, void *value)  deleter 
)
inlinevirtual

Implements leveldb::Cache.

Definition at line 361 of file cache.cc.

362  {
363  const uint32_t hash = HashSlice(key);
364  return shard_[Shard(hash)].Insert(key, hash, value, charge, deleter);
365  }
static uint32_t HashSlice(const Slice &s)
Definition: cache.cc:344
Cache::Handle * Insert(const Slice &key, uint32_t hash, void *value, size_t charge, void(*deleter)(const Slice &key, void *value))
Definition: cache.cc:269
Here is the call graph for this function:

§ Lookup()

virtual Handle* leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::Lookup ( const Slice key)
inlinevirtual

Implements leveldb::Cache.

Definition at line 366 of file cache.cc.

366  {
367  const uint32_t hash = HashSlice(key);
368  return shard_[Shard(hash)].Lookup(key, hash);
369  }
static uint32_t HashSlice(const Slice &s)
Definition: cache.cc:344
Cache::Handle * Lookup(const Slice &key, uint32_t hash)
Definition: cache.cc:255
Here is the call graph for this function:

§ NewId()

virtual uint64_t leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::NewId ( )
inlinevirtual

Implements leveldb::Cache.

Definition at line 381 of file cache.cc.

381  {
382  MutexLock l(&id_mutex_);
383  return ++(last_id_);
384  }

§ Prune()

virtual void leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::Prune ( )
inlinevirtual

Reimplemented from leveldb::Cache.

Definition at line 385 of file cache.cc.

385  {
386  for (int s = 0; s < kNumShards; s++) {
387  shard_[s].Prune();
388  }
389  }
Here is the call graph for this function:

§ Release()

virtual void leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::Release ( Handle handle)
inlinevirtual

Implements leveldb::Cache.

Definition at line 370 of file cache.cc.

370  {
371  LRUHandle* h = reinterpret_cast<LRUHandle*>(handle);
372  shard_[Shard(h->hash)].Release(handle);
373  }
void Release(Cache::Handle *handle)
Definition: cache.cc:264
Here is the call graph for this function:

§ Shard()

static uint32_t leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::Shard ( uint32_t  hash)
inlinestaticprivate

Definition at line 348 of file cache.cc.

348  {
349  return hash >> (32 - kNumShardBits);
350  }

§ TotalCharge()

virtual size_t leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::TotalCharge ( ) const
inlinevirtual

Implements leveldb::Cache.

Definition at line 390 of file cache.cc.

390  {
391  size_t total = 0;
392  for (int s = 0; s < kNumShards; s++) {
393  total += shard_[s].TotalCharge();
394  }
395  return total;
396  }
Here is the call graph for this function:

§ Value()

virtual void* leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::Value ( Handle handle)
inlinevirtual

Implements leveldb::Cache.

Definition at line 378 of file cache.cc.

378  {
379  return reinterpret_cast<LRUHandle*>(handle)->value;
380  }

Member Data Documentation

§ id_mutex_

port::Mutex leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::id_mutex_
private

Definition at line 341 of file cache.cc.

§ last_id_

uint64_t leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::last_id_
private

Definition at line 342 of file cache.cc.

§ shard_

LRUCache leveldb::anonymous_namespace{cache.cc}::ShardedLRUCache::shard_[kNumShards]
private

Definition at line 340 of file cache.cc.


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