LRU (Least Recently Used) cache. More...
#include <roboptim/core/cache.hh>
| Public Types | |
| typedef K | key_t | 
| Type of keys. | |
| typedef detail::const_ref < key_t >::type | const_key_ref | 
| Type of const reference to key. | |
| typedef V | value_t | 
| Type of values. | |
| typedef detail::const_ref < value_t >::type | const_value_ref | 
| Type of const reference to key. | |
| typedef H | hasher_t | 
| Hasher type. | |
| typedef std::size_t | hash_t | 
| Hash type used by the Boost map. | |
| typedef std::vector< value_t > | valuePool_t | 
| typedef std::list< hash_t > | keyTracker_t | 
| List used to track key usage. | |
| typedef hash_t | mapKey_t | 
| Key type for the underlying map. | |
| typedef detail::const_ref < mapKey_t >::type | const_mapKey_ref | 
| typedef boost::unordered_map < mapKey_t, typename valuePool_t::iterator > | map_t | 
| Map from map's 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_key_ref 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_key_ref key) | 
| Access a cached element. | |
| void | insert (const_key_ref key, const_value_ref 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. | |
| Protected Member Functions | |
| hash_t | hash_function (const_key_ref key) const | 
| Hash function used in the cache. | |
LRU (Least Recently Used) cache.
Note that the cache is unidirectional, i.e. the map does not store the actual keys, since this was designed with large vectors in mind.
| 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, H >::const_iterator | 
| typedef detail::const_ref<key_t>::type roboptim::LRUCache< K, V, H >::const_key_ref | 
Type of const reference to key.
| typedef detail::const_ref<mapKey_t>::type roboptim::LRUCache< K, V, H >::const_mapKey_ref | 
| typedef detail::const_ref<value_t>::type roboptim::LRUCache< K, V, H >::const_value_ref | 
Type of const reference to key.
| typedef std::size_t roboptim::LRUCache< K, V, H >::hash_t | 
Hash type used by the Boost map.
| typedef H roboptim::LRUCache< K, V, H >::hasher_t | 
Hasher type.
| typedef map_t::iterator roboptim::LRUCache< K, V, H >::iterator | 
| typedef K roboptim::LRUCache< K, V, H >::key_t | 
Type of keys.
| typedef std::list<hash_t> roboptim::LRUCache< K, V, H >::keyTracker_t | 
List used to track key usage.
Note: we use hashes rather than vectors to prevent costly allocations.
| typedef boost::unordered_map<mapKey_t, typename valuePool_t::iterator> roboptim::LRUCache< K, V, H >::map_t | 
Map from map's key to iterator in the value pool.
| typedef hash_t roboptim::LRUCache< K, V, H >::mapKey_t | 
Key type for the underlying map.
| typedef V roboptim::LRUCache< K, V, H >::value_t | 
Type of values.
| typedef std::vector<value_t> roboptim::LRUCache< K, V, H >::valuePool_t | 
| roboptim::LRUCache< K, V, H >::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, H >::~LRUCache | ( | ) |  [virtual] | 
Destructor.
| LRUCache< K, V, H >::iterator roboptim::LRUCache< K, V, H >::begin | ( | ) | 
Iterator to the beginning of the cache.
| LRUCache< K, V, H >::const_iterator roboptim::LRUCache< K, V, H >::cbegin | ( | ) | const | 
Iterator to the beginning of the cache.
| LRUCache< K, V, H >::const_iterator roboptim::LRUCache< K, V, H >::cend | ( | ) | const | 
Iterator to the end of the cache.
| void roboptim::LRUCache< K, V, H >::clear | ( | ) | 
Clear the cache.
| LRUCache< K, V, H >::iterator roboptim::LRUCache< K, V, H >::end | ( | ) | 
Iterator to the end of the cache.
| LRUCache< K, V, H >::const_iterator roboptim::LRUCache< K, V, H >::find | ( | const_key_ref | key | ) | const | 
Find an element in the cache.
Referenced by roboptim::CachedFunction< T >::cachedFunctionDerivative(), roboptim::CachedFunction< T >::cachedFunctionJacobian(), and roboptim::CachedFunction< T >::impl_compute().
| LRUCache< K, V, H >::hash_t roboptim::LRUCache< K, V, H >::hash_function | ( | const_key_ref | key | ) | const  [protected] | 
Hash function used in the cache.
| key | key to hash. | 
| void roboptim::LRUCache< K, V, H >::insert | ( | const_key_ref | key, | 
| const_value_ref | value | ||
| ) | 
Insert a value into the cache.
| key | key of the element. | 
| value | value of the element. | 
| V & roboptim::LRUCache< K, V, H >::operator[] | ( | const_key_ref | key | ) | 
Access a cached element.
| key | key to the element. | 
| std::ostream & roboptim::LRUCache< K, V, H >::print | ( | std::ostream & | o | ) | const  [virtual] | 
Display the cache on the specified output stream.
| void roboptim::LRUCache< K, V, H >::resize | ( | size_t | size | ) | 
Change the size of the cache.
| size_t roboptim::LRUCache< K, V, H >::size | ( | ) | const | 
Size of the cache.