cxxtools::LruCache< Key, Value > Class Template Reference

Implements a lru cache. More...

#include <cxxtools/lrucache.h>

Classes

struct  Data

Public Types

typedef DataType::size_type size_type
typedef Value value_type

Public Member Functions

 LruCache (size_type maxElements_)
size_type size () const
 returns the number of elements currently in the cache
size_type getMaxElements () const
 returns the maximum number of elements in the cache
void setMaxElements (size_type maxElements_)
bool erase (const Key &key)
 removes a element from the cache and returns true, if found
void clear (bool stats=false)
 clears the cache.
Value & put (const Key &key, const Value &value)
 puts a new element in the cache.
Value * getptr (const Key &key)
std::pair< bool, Value > getx (const Key &key, Value def=Value())
 returns a pair of values - a flag, if the value was found and the value if found or the passed default otherwise.
Value get (const Key &key, Value def=Value())
 returns the value to a key or the passed default value if not found.
unsigned getHits () const
 returns the number of hits.
unsigned getMisses () const
 returns the number of misses.
double hitRatio () const
 returns the cache hit ratio between 0 and 1.
double fillfactor () const
 returns the ratio, between held elements and maximum elements.

Detailed Description

template<typename Key, typename Value>
class cxxtools::LruCache< Key, Value >

Implements a lru cache.

Member Typedef Documentation

template<typename Key , typename Value >
typedef DataType::size_type cxxtools::LruCache< Key, Value >::size_type
template<typename Key , typename Value >
typedef Value cxxtools::LruCache< Key, Value >::value_type

Constructor & Destructor Documentation

template<typename Key , typename Value >
cxxtools::LruCache< Key, Value >::LruCache ( size_type  maxElements_)
inlineexplicit

Member Function Documentation

template<typename Key , typename Value >
void cxxtools::LruCache< Key, Value >::clear ( bool  stats = false)
inline

clears the cache.

template<typename Key , typename Value >
bool cxxtools::LruCache< Key, Value >::erase ( const Key &  key)
inline

removes a element from the cache and returns true, if found

template<typename Key , typename Value >
double cxxtools::LruCache< Key, Value >::fillfactor ( ) const
inline

returns the ratio, between held elements and maximum elements.

template<typename Key , typename Value >
Value cxxtools::LruCache< Key, Value >::get ( const Key &  key,
Value  def = Value() 
)
inline

returns the value to a key or the passed default value if not found.

If the value is found it is a cahce hit and pushed to the top of the list.

template<typename Key , typename Value >
unsigned cxxtools::LruCache< Key, Value >::getHits ( ) const
inline

returns the number of hits.

template<typename Key , typename Value >
size_type cxxtools::LruCache< Key, Value >::getMaxElements ( ) const
inline

returns the maximum number of elements in the cache

template<typename Key , typename Value >
unsigned cxxtools::LruCache< Key, Value >::getMisses ( ) const
inline

returns the number of misses.

template<typename Key , typename Value >
Value* cxxtools::LruCache< Key, Value >::getptr ( const Key &  key)
inline
template<typename Key , typename Value >
std::pair<bool, Value> cxxtools::LruCache< Key, Value >::getx ( const Key &  key,
Value  def = Value() 
)
inline

returns a pair of values - a flag, if the value was found and the value if found or the passed default otherwise.

If the value is found it is a cache hit and pushed to the top of the list.

template<typename Key , typename Value >
double cxxtools::LruCache< Key, Value >::hitRatio ( ) const
inline

returns the cache hit ratio between 0 and 1.

template<typename Key , typename Value >
Value& cxxtools::LruCache< Key, Value >::put ( const Key &  key,
const Value &  value 
)
inline

puts a new element in the cache.

If the element is already found in the cache, it is considered a cache hit and pushed to the top of the list.

template<typename Key , typename Value >
void cxxtools::LruCache< Key, Value >::setMaxElements ( size_type  maxElements_)
inline
template<typename Key , typename Value >
size_type cxxtools::LruCache< Key, Value >::size ( ) const
inline

returns the number of elements currently in the cache


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