LRU (Least Recently Used) cache. More...
#include <roboptim/core/cache.hh>
Public Types | |
typedef K | key_t |
Type of keys. | |
typedef V | value_t |
Type of values. | |
typedef std::list< key_t > | keyTracker_t |
typedef std::vector< value_t > | valuePool_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. |
LRU (Least Recently Used) cache.
K | type for keys. |
V | type for values. Some of the ideas used here come from Tim Day's "LRU cache implementation in C++" (http://timday.bitbucket.org/lru.html) |
typedef map_t::const_iterator roboptim::LRUCache< K, V >::const_iterator |
typedef map_t::iterator roboptim::LRUCache< K, V >::iterator |
typedef K roboptim::LRUCache< K, V >::key_t |
Type of keys.
typedef std::list<key_t> roboptim::LRUCache< K, V >::keyTracker_t |
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.
typedef V roboptim::LRUCache< K, V >::value_t |
Type of values.
typedef std::vector<value_t> roboptim::LRUCache< K, V >::valuePool_t |
roboptim::LRUCache< K, V >::LRUCache | ( | size_t | size = 10 | ) |
Constructor.
Note: all the memory is allocated in the constructor.
size | maximum size of the cache. |
roboptim::LRUCache< K, V >::~LRUCache | ( | ) | [virtual] |
Destructor.
LRUCache< K, V >::iterator roboptim::LRUCache< K, V >::begin | ( | ) |
Iterator to the beginning of the cache.
LRUCache< K, V >::const_iterator roboptim::LRUCache< K, V >::cbegin | ( | ) | const |
Iterator to the beginning of the cache.
LRUCache< K, V >::const_iterator roboptim::LRUCache< K, V >::cend | ( | ) | const |
Iterator to the end of the cache.
void roboptim::LRUCache< K, V >::clear | ( | ) |
Clear the cache.
LRUCache< K, V >::iterator roboptim::LRUCache< K, V >::end | ( | ) |
Iterator to the end of the cache.
LRUCache< K, V >::const_iterator roboptim::LRUCache< K, V >::find | ( | const K & | key | ) | const |
Find an element in the cache.
Referenced by roboptim::CachedFunction< T >::impl_compute(), roboptim::CachedFunction< T >::impl_derivative(), and roboptim::CachedFunction< T >::impl_jacobian().
void roboptim::LRUCache< K, V >::insert | ( | const K & | key, |
const V & | value | ||
) |
Insert a value into the cache.
key | key of the element. |
value | value of the element. |
V & roboptim::LRUCache< K, V >::operator[] | ( | const K & | key | ) |
Access a cached element.
key | key to the element. |
std::ostream & roboptim::LRUCache< K, V >::print | ( | std::ostream & | o | ) | const [virtual] |
Display the cache on the specified output stream.
void roboptim::LRUCache< K, V >::resize | ( | size_t | size | ) |
Change the size of the cache.
size_t roboptim::LRUCache< K, V >::size | ( | ) | const |
Size of the cache.