libosmscout
0.1
|
#include <Cache.h>
Classes | |
struct | CacheEntry |
An individual entry in the cache. More... | |
class | ValueSizer |
ValueSizer returns the size (in bytes) of an individual cache value. More... | |
Public Types | |
using | CacheRef = typename OrderList::iterator |
using | Map = std::unordered_map< K, typename OrderList::iterator > |
using | OrderList = std::list< CacheEntry > |
Public Member Functions | |
Cache (size_t maxSize) | |
Create a new cache object with the given max size. More... | |
void | DumpStatistics (const char *cacheName, const ValueSizer &sizer) |
Dump some cache statistics to std::cout. More... | |
void | Flush () |
Completely flush the cache removing all entries from it. More... | |
bool | GetEntry (const K &key, CacheRef &reference) |
Getting the value with the given key from cache. More... | |
size_t | GetMaxSize () const |
Returns the maximum size of the cache. More... | |
size_t | GetMemory (const ValueSizer &sizer) const |
size_t | GetSize () const |
Returns the current size of the cache. More... | |
bool | IsActive () const |
Returns if the cache is active (maxSize > 0) More... | |
Cache::CacheRef | SetEntry (const CacheEntry &entry) |
Set or update the cache with the given value for the given key. More... | |
void | SetMaxSize (size_t maxSize) |
Set a new cache max size, possible striping the oldest entries from cache if the new size is smaller than the old one. More... | |
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.
Referenced by osmscout::AreaAreaIndex::DumpStatistics().
|
inline |
Completely flush the cache removing all entries from it.
Referenced by osmscout::AreaAreaIndex::Close(), and osmscout::AreaAreaIndex::FlushCache().
|
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)
Referenced by osmscout::Cache< FileOffset, std::shared_ptr< osmscout::Intersection > >::GetEntry(), and osmscout::Cache< FileOffset, std::shared_ptr< osmscout::Intersection > >::SetEntry().
|
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.