VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Protected Types | Protected Attributes | Private Member Functions | Private Attributes
makVrv::LRUCache< K, T, COMPARE > Class Template Reference

template<typename K, typename T, typename COMPARE = std::less<K>>
class makVrv::LRUCache< K, T, COMPARE >

Least-recently-used cache class.

K = key type, T = value type

usage: LRUCache<K,T> cache; cache.put( key, value ); LRUCache.Record rec = cache.get( key ); if ( rec.valid() ) const T& value = rec.value();

Inheritance diagram for makVrv::LRUCache< K, T, COMPARE >:
Inheritance graph
[legend]

Classes

struct  Functor
 
struct  Record
 

Public Member Functions

 LRUCache (unsigned max=100)
 
 LRUCache (bool threadsafe, unsigned max=100)
 
virtual ~LRUCache ()
 
void insert (const K &key, const T &value)
 
bool get (const K &key, Record &out)
 
bool has (const K &key)
 
void erase (const K &key)
 
void clear ()
 
void setMaxSize (unsigned max)
 
unsigned getMaxSize () const
 
CacheStats getStats () const
 
void iterate (Functor &functor) const
 
void enableDebug (bool enable)
 

Protected Types

typedef std::list< K >::iterator lru_iter
 
typedef std::list< K > lru_type
 
typedef std::pair< T, lru_itermap_value_type
 
typedef std::map< K,
map_value_type
map_type
 
typedef map_type::iterator map_iter
 
typedef map_type::const_iterator map_const_iter
 

Protected Attributes

map_type _map
 
lru_type _lru
 
unsigned _max
 
unsigned _buf
 
unsigned _queries
 
unsigned _hits
 
bool _threadsafe
 
Threading::Mutex _mutex
 

Private Member Functions

void insert_impl (const K &key, const T &value)
 
void get_impl (const K &key, Record &result)
 
bool has_impl (const K &key)
 
void erase_impl (const K &key)
 
void clear_impl ()
 
void setMaxSize_impl (unsigned max)
 
void iterate_impl (Functor &f) const
 

Private Attributes

bool myDebug
 

Member Typedef Documentation

template<typename K, typename T, typename COMPARE = std::less<K>>
typedef std::list<K>::iterator makVrv::LRUCache< K, T, COMPARE >::lru_iter
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
typedef std::list<K> makVrv::LRUCache< K, T, COMPARE >::lru_type
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
typedef std::pair<T, lru_iter> makVrv::LRUCache< K, T, COMPARE >::map_value_type
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
typedef std::map<K, map_value_type> makVrv::LRUCache< K, T, COMPARE >::map_type
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
typedef map_type::iterator makVrv::LRUCache< K, T, COMPARE >::map_iter
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
typedef map_type::const_iterator makVrv::LRUCache< K, T, COMPARE >::map_const_iter
protected

Constructor & Destructor Documentation

template<typename K, typename T, typename COMPARE = std::less<K>>
makVrv::LRUCache< K, T, COMPARE >::LRUCache ( unsigned  max = 100)
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
makVrv::LRUCache< K, T, COMPARE >::LRUCache ( bool  threadsafe,
unsigned  max = 100 
)
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
virtual makVrv::LRUCache< K, T, COMPARE >::~LRUCache ( )
inlinevirtual

dtor

Member Function Documentation

template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::insert ( const K &  key,
const T &  value 
)
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
bool makVrv::LRUCache< K, T, COMPARE >::get ( const K &  key,
Record out 
)
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
bool makVrv::LRUCache< K, T, COMPARE >::has ( const K &  key)
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::erase ( const K &  key)
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::clear ( void  )
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::setMaxSize ( unsigned  max)
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
unsigned makVrv::LRUCache< K, T, COMPARE >::getMaxSize ( ) const
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
CacheStats makVrv::LRUCache< K, T, COMPARE >::getStats ( ) const
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::iterate ( Functor functor) const
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::enableDebug ( bool  enable)
inline
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::insert_impl ( const K &  key,
const T &  value 
)
inlineprivate
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::get_impl ( const K &  key,
Record result 
)
inlineprivate
template<typename K, typename T, typename COMPARE = std::less<K>>
bool makVrv::LRUCache< K, T, COMPARE >::has_impl ( const K &  key)
inlineprivate
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::erase_impl ( const K &  key)
inlineprivate
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::clear_impl ( )
inlineprivate
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::setMaxSize_impl ( unsigned  max)
inlineprivate
template<typename K, typename T, typename COMPARE = std::less<K>>
void makVrv::LRUCache< K, T, COMPARE >::iterate_impl ( Functor f) const
inlineprivate

Member Data Documentation

template<typename K, typename T, typename COMPARE = std::less<K>>
map_type makVrv::LRUCache< K, T, COMPARE >::_map
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
lru_type makVrv::LRUCache< K, T, COMPARE >::_lru
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
unsigned makVrv::LRUCache< K, T, COMPARE >::_max
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
unsigned makVrv::LRUCache< K, T, COMPARE >::_buf
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
unsigned makVrv::LRUCache< K, T, COMPARE >::_queries
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
unsigned makVrv::LRUCache< K, T, COMPARE >::_hits
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
bool makVrv::LRUCache< K, T, COMPARE >::_threadsafe
protected
template<typename K, typename T, typename COMPARE = std::less<K>>
Threading::Mutex makVrv::LRUCache< K, T, COMPARE >::_mutex
mutableprotected
template<typename K, typename T, typename COMPARE = std::less<K>>
bool makVrv::LRUCache< K, T, COMPARE >::myDebug
private

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

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)