Least-Recently-Used cache. More...
#include <lru_cache.hpp>
Public Types | |
using | generator = GENERATOR |
using | key_type = KEY |
using | value_type = VALUE |
Public Member Functions | |
LruCache (generator g, std::size_t capacity) | |
value_type & | operator[] (const key_type &key) |
Access a cache entry. | |
Private Types | |
using | list_type = std::list< key_type > |
using | entry_type = std::pair< value_type, typename list_type::iterator > |
using | map_type = std::unordered_map< key_type, entry_type > |
Private Member Functions | |
value_type & | add (const key_type &k) |
value_type & | refresh (typename map_type::iterator found) |
void | remove () |
Private Attributes | |
generator | m_generator |
std::size_t | m_capacity |
list_type | m_index |
map_type | m_cache |
Least-Recently-Used cache.
If an entry is accessed which is not yet cached, it will created by invocation of the generator function.
KEY | key type |
VALUE | value_type, i.e. type of cache entries |
GENERATOR | generator function for creating values from key |
Definition at line 23 of file lru_cache.hpp.
|
private |
Definition at line 61 of file lru_cache.hpp.
using vanetza::LruCache< KEY, VALUE, GENERATOR >::generator = GENERATOR |
Definition at line 26 of file lru_cache.hpp.
using vanetza::LruCache< KEY, VALUE, GENERATOR >::key_type = KEY |
Definition at line 27 of file lru_cache.hpp.
|
private |
Definition at line 60 of file lru_cache.hpp.
|
private |
Definition at line 62 of file lru_cache.hpp.
using vanetza::LruCache< KEY, VALUE, GENERATOR >::value_type = VALUE |
Definition at line 28 of file lru_cache.hpp.
|
inline |
g | user-defined generator function |
capacity | maximum number of cache entries |
Definition at line 34 of file lru_cache.hpp.
|
inlineprivate |
Definition at line 64 of file lru_cache.hpp.
|
inline |
Access a cache entry.
If cache entry does not yet exist it will be created. The least recently accessed entry might get dropped.
key | identifier of cache entry |
Definition at line 49 of file lru_cache.hpp.
|
inlineprivate |
Definition at line 77 of file lru_cache.hpp.
|
inlineprivate |
Definition at line 84 of file lru_cache.hpp.
|
private |
Definition at line 95 of file lru_cache.hpp.
|
private |
Definition at line 93 of file lru_cache.hpp.
|
private |
Definition at line 92 of file lru_cache.hpp.
|
private |
Definition at line 94 of file lru_cache.hpp.