LRU (Least Recently Used) cache. More...
#include <roboptim/core/fwd.hh>
Public Types | |
typedef K | key_t |
Type of keys. More... | |
typedef detail::const_ref < key_t >::type | const_key_ref |
Type of const reference to key. More... | |
typedef V | value_t |
Type of values. More... | |
typedef detail::const_ref < value_t >::type | const_value_ref |
Type of const reference to key. More... | |
typedef H | hasher_t |
Hasher type. More... | |
typedef std::size_t | hash_t |
Hash type used by the Boost map. More... | |
typedef detail::aligned_vector_type < value_t >::type | valuePool_t |
Pool of values stored as std::vector. More... | |
typedef std::list< hash_t > | keyTracker_t |
List used to track key usage. More... | |
typedef hash_t | mapKey_t |
Key type for the underlying map. More... | |
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. More... | |
typedef map_t::const_iterator | const_iterator |
typedef map_t::iterator | iterator |
Public Member Functions | |
LRUCache (size_t size=10) | |
Constructor. More... | |
virtual | ~LRUCache () |
Destructor. More... | |
size_t | size () const |
Size of the cache. More... | |
void | resize (size_t size) |
Change the size of the cache. More... | |
const_iterator | find (const_key_ref key) const |
Find an element in the cache. More... | |
iterator | begin () |
Iterator to the beginning of the cache. More... | |
iterator | end () |
Iterator to the end of the cache. More... | |
const_iterator | cbegin () const |
Iterator to the beginning of the cache. More... | |
const_iterator | cend () const |
Iterator to the end of the cache. More... | |
V & | operator[] (const_key_ref key) |
Access a cached element. More... | |
void | insert (const_key_ref key, const_value_ref value) |
Insert a value into the cache. More... | |
void | clear () |
Clear the cache. More... | |
virtual std::ostream & | print (std::ostream &) const |
Display the cache on the specified output stream. More... | |
Protected Member Functions | |
hash_t | hash_function (const_key_ref key) const |
Hash function used in the cache. More... | |
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 detail::aligned_vector_type<value_t>::type roboptim::LRUCache< K, V, H >::valuePool_t |
Pool of values stored as std::vector.
The container is properly aligned if an Eigen type is used.
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. |
|
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.
Referenced by roboptim::CachedFunction< T >::cachedFunctionJacobian().
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 >::cachedFunctionJacobian(), and roboptim::CachedFunction< T >::impl_compute().
|
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. |
|
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.