#include <Cache.h>
|
| Cache (size_t _maxCacheSize=10000, double _cacheReductionAmount=0.2, double _decay=0.98) |
|
| Cache (const Cache &)=delete |
|
Cache & | operator= (const Cache &)=delete |
|
| ~Cache () |
|
std::pair< Ref, bool > | cache (T *_toCache, bool(*_canBeUpdated)(const T &, const T &)=&returnFalse< T >, void(*_update)(const T &, const T &)=&doNothing< T >) |
| Caches the given object. More...
|
|
void | reg (Ref _refStoragePos) |
| Registers the entry to the given reference. More...
|
|
void | dereg (Ref _refStoragePos) |
| Deregisters the entry to the given reference. More...
|
|
void | rehash (Ref _refStoragePos) |
| Removes and reinserts the entry with the given reference, after its hash value is recalculated. More...
|
|
void | decayActivity () |
| Decays all activities by increasing the activity increment. More...
|
|
void | strengthenActivity (Ref _refStoragePos) |
| Strenghtens the activity of the entry in the cache with the given reference, by increasing its activity. More...
|
|
void | print (std::ostream &_out=std::cout) const |
| Prints all information stored in this cache to std::cout. More...
|
|
const T & | get (Ref _refStoragePos) const |
|
template<typename T>
class carl::Cache< T >
Definition at line 47 of file Cache.h.
◆ Container
◆ Ref
◆ Cache() [1/2]
template<typename T >
carl::Cache< T >::Cache |
( |
size_t |
_maxCacheSize = 10000 , |
|
|
double |
_cacheReductionAmount = 0.2 , |
|
|
double |
_decay = 0.98 |
|
) |
| |
|
explicit |
◆ Cache() [2/2]
◆ ~Cache()
◆ cache()
template<typename T >
std::pair<Ref,bool> carl::Cache< T >::cache |
( |
T * |
_toCache, |
|
|
bool(*)(const T &, const T &) |
_canBeUpdated = &returnFalse< T > , |
|
|
void(*)(const T &, const T &) |
_update = &doNothing< T > |
|
) |
| |
Caches the given object.
- Parameters
-
_toCache | The object to cache. |
_canBeUpdated | A function, which determines whether, in the case an equal object has already been cached, the given object can update the information in this already cached object. |
_update | A function which updates an object in the cache, which is equal to the given object, by the information in the given object. After this function has been applied, the corresponding entry in the cache will be reinserted in it after been rehashed. |
- Returns
- The reference of the entry, which can be used outside this class to access the entry.
◆ checkNumOfUnusedEntries()
template<typename T >
bool carl::Cache< T >::checkNumOfUnusedEntries |
( |
| ) |
const |
|
inlineprivate |
◆ clean()
Removes a certain amount of unused entries in the cache.
◆ decayActivity()
Decays all activities by increasing the activity increment.
◆ dereg()
Deregisters the entry to the given reference.
It mainly decreases the usage counter of this entry in the cache.
- Parameters
-
_refStoragePos | The reference of the entry to deregister. |
◆ erase() [1/2]
Removes the entry at the given position in the cache.
- Parameters
-
_toRemove | The position to the entry to remove from the cache. |
- Returns
Definition at line 225 of file Cache.h.
◆ erase() [2/2]
template<typename T >
Container::iterator carl::Cache< T >::erase |
( |
typename Container::iterator |
_toRemove | ) |
|
|
inlineprivate |
Removes the entry at the given position in the cache.
- Parameters
-
_toRemove | The position to the entry to remove from the cache. |
- Returns
- An iterator to the entry in the cache right after the entry which has to be removed.
Definition at line 252 of file Cache.h.
◆ get()
- Parameters
-
_refStoragePos | The reference of the entry to obtain the object from. |
- Returns
- The object in the entry with the given reference.
Definition at line 205 of file Cache.h.
◆ hasDuplicates()
template<typename T >
bool carl::Cache< T >::hasDuplicates |
( |
const std::vector< Ref > & |
_vec | ) |
const |
|
inlineprivate |
◆ operator=()
◆ print()
template<typename T >
void carl::Cache< T >::print |
( |
std::ostream & |
_out = std::cout | ) |
const |
Prints all information stored in this cache to std::cout.
- Parameters
-
_out | The stream to print on. |
◆ reg()
Registers the entry to the given reference.
It mainly increases the usage counter of this entry in the cache.
- Parameters
-
_refStoragePos | The reference of the entry to register. |
◆ rehash()
Removes and reinserts the entry with the given reference, after its hash value is recalculated.
- Parameters
-
_refStoragePos | The reference of the entry to apply the given function to. |
- Returns
- The new reference.
◆ strengthenActivity()
Strenghtens the activity of the entry in the cache with the given reference, by increasing its activity.
- Parameters
-
_refStoragePos | The reference of the entry in the cache to strengthen its activity. |
◆ sumOfAllUsageCounts()
◆ mActivityDecrementFactor
template<typename T >
double carl::Cache< T >::mActivityDecrementFactor = 1e-100 |
|
private |
The factor multiplied to all activities in order to rescale (decrease) them.
Definition at line 122 of file Cache.h.
◆ mActivityIncrement
The reciprocal of the factor to multiply an activity with in order to increase it.
This member can increased by a user interface.
Definition at line 106 of file Cache.h.
◆ mActivityThreshold
The threshold limiting the maximum activity.
If this threshold is exceeded, all activities are rescaled.
Definition at line 117 of file Cache.h.
◆ mCache
The container storing all cached entries.
It maps the objects to store to cache information, which cover a usage counter, the position in mCacheRefs, being the entries reference, and the activity of this entry.
Definition at line 133 of file Cache.h.
◆ mCacheReductionAmount
The percentage of the cache, which shall be removed at best, if the cache size exceeds the threshold.
(NOT YET USED)
Definition at line 95 of file Cache.h.
◆ mCacheRefs
Stores at the reference of an entry in the cache an iterator to this entry.
This reference can be used to access the entry outside this class.
Definition at line 139 of file Cache.h.
◆ mDecay
The decay (between 0.9 and 1.0) of the given increments on activities.
It is applied by increasing the increment by multiplying this members reciprocal to it.
Definition at line 112 of file Cache.h.
◆ mMaxActivity
The threshold for the maximum activity.
In case it is exceeded, all activities are rescaled.
Definition at line 100 of file Cache.h.
◆ mMaxCacheSize
The threshold for the cache's size which should not be exceeded, except more of the cache entries are still in use.
Definition at line 85 of file Cache.h.
◆ mMutex
A mutex for situation where any member is changed.
TODO: Refine the locking-situations.
Definition at line 127 of file Cache.h.
◆ mNumOfUnusedEntries
The current number of entries in the cache, which are not used.
Definition at line 90 of file Cache.h.
◆ mUnusedPositionsInCacheRefs
A stack containing free references, which have been used before but freed now.
Definition at line 141 of file Cache.h.
◆ NO_REF
The documentation for this class was generated from the following file: