roboptim::LRUCache< K, V > Class Template Reference

LRU (Least Recently Used) cache. More...

#include <roboptim/core/cache.hh>

List of all members.

Public Types

typedef K key_t
 Type of keys.
typedef V value_t
 Type of values.
typedef std::list< key_tkeyTracker_t
typedef std::vector< value_tvaluePool_t
typedef boost::unordered_map
< key_t, typename
valuePool_t::iterator > 
map_t
 Map from key to iterator in the value pool.
typedef map_t::const_iterator const_iterator
typedef map_t::iterator iterator

Public Member Functions

 LRUCache (size_t size=10)
 Constructor.
virtual ~LRUCache ()
 Destructor.
size_t size () const
 Size of the cache.
void resize (size_t size)
 Change the size of the cache.
const_iterator find (const K &key) const
 Find an element in the cache.
iterator begin ()
 Iterator to the beginning of the cache.
iterator end ()
 Iterator to the end of the cache.
const_iterator cbegin () const
 Iterator to the beginning of the cache.
const_iterator cend () const
 Iterator to the end of the cache.
V & operator[] (const K &key)
 Access a cached element.
void insert (const K &key, const V &value)
 Insert a value into the cache.
void clear ()
 Clear the cache.
virtual std::ostream & print (std::ostream &) const
 Display the cache on the specified output stream.

Detailed Description

template<typename K, typename V>
class roboptim::LRUCache< K, V >

LRU (Least Recently Used) cache.

Template Parameters:
Ktype for keys.
Vtype for values. Some of the ideas used here come from Tim Day's "LRU cache implementation in C++" (http://timday.bitbucket.org/lru.html)

Member Typedef Documentation

template<typename K, typename V>
typedef map_t::const_iterator roboptim::LRUCache< K, V >::const_iterator
template<typename K, typename V>
typedef map_t::iterator roboptim::LRUCache< K, V >::iterator
template<typename K, typename V>
typedef K roboptim::LRUCache< K, V >::key_t

Type of keys.

template<typename K, typename V>
typedef std::list<key_t> roboptim::LRUCache< K, V >::keyTracker_t
template<typename K, typename V>
typedef boost::unordered_map<key_t, typename valuePool_t::iterator> roboptim::LRUCache< K, V >::map_t

Map from key to iterator in the value pool.

template<typename K, typename V>
typedef V roboptim::LRUCache< K, V >::value_t

Type of values.

template<typename K, typename V>
typedef std::vector<value_t> roboptim::LRUCache< K, V >::valuePool_t

Constructor & Destructor Documentation

template<typename K , typename V >
roboptim::LRUCache< K, V >::LRUCache ( size_t  size = 10)

Constructor.

Note: all the memory is allocated in the constructor.

Parameters:
sizemaximum size of the cache.
template<typename K , typename V >
roboptim::LRUCache< K, V >::~LRUCache ( ) [virtual]

Destructor.


Member Function Documentation

template<typename K , typename V >
LRUCache< K, V >::iterator roboptim::LRUCache< K, V >::begin ( )

Iterator to the beginning of the cache.

template<typename K , typename V >
LRUCache< K, V >::const_iterator roboptim::LRUCache< K, V >::cbegin ( ) const

Iterator to the beginning of the cache.

template<typename K , typename V >
LRUCache< K, V >::const_iterator roboptim::LRUCache< K, V >::cend ( ) const

Iterator to the end of the cache.

template<typename K , typename V >
void roboptim::LRUCache< K, V >::clear ( )

Clear the cache.

template<typename K , typename V >
LRUCache< K, V >::iterator roboptim::LRUCache< K, V >::end ( )

Iterator to the end of the cache.

template<typename K, typename V >
LRUCache< K, V >::const_iterator roboptim::LRUCache< K, V >::find ( const K &  key) const
template<typename K, typename V>
void roboptim::LRUCache< K, V >::insert ( const K &  key,
const V &  value 
)

Insert a value into the cache.

Parameters:
keykey of the element.
valuevalue of the element.
template<typename K, typename V >
V & roboptim::LRUCache< K, V >::operator[] ( const K &  key)

Access a cached element.

Parameters:
keykey to the element.
Returns:
reference to the element.
template<typename K , typename V >
std::ostream & roboptim::LRUCache< K, V >::print ( std::ostream &  o) const [virtual]

Display the cache on the specified output stream.

template<typename K , typename V >
void roboptim::LRUCache< K, V >::resize ( size_t  size)

Change the size of the cache.

template<typename K , typename V >
size_t roboptim::LRUCache< K, V >::size ( ) const

Size of the cache.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines