|
libosmscout 1.1.1
|
#include <libosmscout/include/osmscout/util/Cache.h>
Classes | |
| struct | CacheEntry |
| class | ValueSizer |
Public Types | |
| using | OrderList = std::list<CacheEntry> |
| using | CacheRef = typename OrderList::iterator |
| using | Map = std::unordered_map<K, typename OrderList::iterator> |
Public Member Functions | |
| Cache (size_t maxSize) | |
| bool | IsActive () const |
| bool | GetEntry (const K &key, CacheRef &reference) |
| Cache::CacheRef | SetEntry (const CacheEntry &entry) |
| void | SetMaxSize (size_t maxSize) |
| size_t | GetMaxSize () const |
| void | Flush () |
| size_t | GetSize () const |
| size_t | GetMemory (const ValueSizer &sizer) const |
| void | DumpStatistics (const char *cacheName, const ValueSizer &sizer) |
Generic FIFO cache implementation with O(n log n) semantic.
Template parameter class K holds the key value (must be a numerical value), parameter class V holds the data class that is to be cached, and parameter IK holds the internal key value, must be an unsigned value, default is PageId.
Implementation details: If std::unordered_map ist available we use this for fast detection (O(1)) if an object is already in the cast. If it is not available, we use a vector as a hashtable via the key value with list as entry type for hash code conflict handling.
| using osmscout::Cache< K, V, IK >::CacheRef = typename OrderList::iterator |
| using osmscout::Cache< K, V, IK >::Map = std::unordered_map<K, typename OrderList::iterator> |
| using osmscout::Cache< K, V, IK >::OrderList = std::list<CacheEntry> |
|
inlineexplicit |
Create a new cache object with the given max size.
|
inline |
Dump some cache statistics to std::cout.
|
inline |
Completely flush the cache removing all entries from it.
|
inline |
Getting the value with the given key from cache.
If there is no valued stored with the given key, false will be returned and the reference will be untouched.
If there is a value with the given key, reference will return a reference to the value and the value will moved to the front position of the cache to assure FIFO behaviour.
|
inline |
Returns the maximum size of the cache
|
inline |
|
inline |
Returns the current size of the cache.
|
inline |
Returns if the cache is active (maxSize > 0)
|
inline |
Set or update the cache with the given value for the given key.
If the key is not available in the cache the value will be added to the front of the cache (FIFO semantic) else the value will be updated (also moving it to the front of the cache (FIFO again).
|
inline |
Set a new cache max size, possible striping the oldest entries from cache if the new size is smaller than the old one.