UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | List of all members
LRUCache< Key, Data, Sizefn > Class Template Reference

Template cache with an LRU removal policy. More...

#include <lru_cache.h>

Public Types

typedef std::list< std::pair
< Key, Data > > 
List
 Main cache storage typedef.
 
typedef List::iterator List_Iter
 Main cache iterator.
 
typedef List::const_iterator List_cIter
 Main cache iterator (const)
 
typedef std::vector< Key > Key_List
 List of keys.
 
typedef Key_List::iterator Key_List_Iter
 Main cache iterator.
 
typedef Key_List::const_iterator Key_List_cIter
 Main cache iterator (const)
 
typedef std::map< Key, List_IterMap
 Index typedef.
 
typedef std::pair< Key, List_IterPair
 Pair of Map elements.
 
typedef Map::iterator Map_Iter
 Index iterator.
 
typedef Map::const_iterator Map_cIter
 Index iterator (const)
 

Public Member Functions

 LRUCache (const unsigned long Size)
 Creates a cache that holds at most Size worth of elements. More...
 
 LRUCache (const LRUCache &that)
 
LRUCacheoperator= (const LRUCache &that)
 
 ~LRUCache ()
 Destructor - cleans up both index and storage.
 
unsigned long size (void) const
 Gets the current abstract size of the cache. More...
 
unsigned long max_size (void) const
 Gets the maximum sbstract size of the cache. More...
 
void clear (void)
 Clears all storage and indices.
 
bool exists (const Key &key) const
 Checks for the existance of a key in the cache. More...
 
void remove (const Key &key)
 Removes a key-data pair from the cache. More...
 
void touch (const Key &key)
 Touches a key in the Cache and makes it the most recently used. More...
 
Data * fetch_ptr (const Key &key, bool touch_data=true)
 Fetches a pointer to cache data. More...
 
Data fetch (const Key &key, bool touch_data=true)
 Fetches a copy of cached data. More...
 
bool fetch (const Key &key, Data &data, bool touch_data=true)
 Fetches a pointer to cache data. More...
 
void insert (const Key &key, const Data &data)
 Inserts a key-data pair into the cache and removes entries if neccessary. More...
 
void info ()
 
const Key_List get_all_keys (void)
 Get a list of keys. More...
 

Detailed Description

template<class Key, class Data, class Sizefn = Countfn< Data >>
class LRUCache< Key, Data, Sizefn >

Template cache with an LRU removal policy.

This template creats a simple collection of key-value pairs that grows until the size specified at construction is reached and then begins discard the Least Recently Used element on each insertion.

Constructor & Destructor Documentation

template<class Key, class Data, class Sizefn = Countfn< Data >>
LRUCache< Key, Data, Sizefn >::LRUCache ( const unsigned long  Size)
inline

Creates a cache that holds at most Size worth of elements.

Parameters
Sizemaximum size of cache

Member Function Documentation

template<class Key, class Data, class Sizefn = Countfn< Data >>
bool LRUCache< Key, Data, Sizefn >::exists ( const Key &  key) const
inline

Checks for the existance of a key in the cache.

Parameters
keyto check for
Returns
bool indicating whether or not the key was found.
template<class Key, class Data, class Sizefn = Countfn< Data >>
Data LRUCache< Key, Data, Sizefn >::fetch ( const Key &  key,
bool  touch_data = true 
)
inline

Fetches a copy of cached data.

Parameters
keyto fetch data for
touch_datawhether or not to touch the data
Returns
copy of the data or an empty Data object if not found
template<class Key, class Data, class Sizefn = Countfn< Data >>
bool LRUCache< Key, Data, Sizefn >::fetch ( const Key &  key,
Data &  data,
bool  touch_data = true 
)
inline

Fetches a pointer to cache data.

Parameters
keyto fetch data for
datato fetch data into
touch_datawhether or not to touch the data
Returns
whether or not data was filled in
template<class Key, class Data, class Sizefn = Countfn< Data >>
Data* LRUCache< Key, Data, Sizefn >::fetch_ptr ( const Key &  key,
bool  touch_data = true 
)
inline

Fetches a pointer to cache data.

Parameters
keyto fetch data for
touchwhether or not to touch the data
Returns
pointer to data or NULL on error
template<class Key, class Data, class Sizefn = Countfn< Data >>
const Key_List LRUCache< Key, Data, Sizefn >::get_all_keys ( void  )
inline

Get a list of keys.

Returns
list of the current keys.
template<class Key, class Data, class Sizefn = Countfn< Data >>
void LRUCache< Key, Data, Sizefn >::insert ( const Key &  key,
const Data &  data 
)
inline

Inserts a key-data pair into the cache and removes entries if neccessary.

Parameters
keyobject key for insertion
dataobject data for insertion
Note
This function checks key existance and touches the key if it already exists.
template<class Key, class Data, class Sizefn = Countfn< Data >>
unsigned long LRUCache< Key, Data, Sizefn >::max_size ( void  ) const
inline

Gets the maximum sbstract size of the cache.

Returns
maximum size
template<class Key, class Data, class Sizefn = Countfn< Data >>
void LRUCache< Key, Data, Sizefn >::remove ( const Key &  key)
inline

Removes a key-data pair from the cache.

Parameters
keyto be removed
template<class Key, class Data, class Sizefn = Countfn< Data >>
unsigned long LRUCache< Key, Data, Sizefn >::size ( void  ) const
inline

Gets the current abstract size of the cache.

Returns
current size
template<class Key, class Data, class Sizefn = Countfn< Data >>
void LRUCache< Key, Data, Sizefn >::touch ( const Key &  key)
inline

Touches a key in the Cache and makes it the most recently used.

Parameters
keyto be touched

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