template<typename CachedKey, typename CachedValue, typename HashFunc = std::hash<CachedKey>>
class retdec::llvmir2hll::Caching< CachedKey, CachedValue, HashFunc >
A mixin for enabling caching of computed results.
- Template Parameters
-
CachedKey | Key with which a value is associated. |
CachedValue | Value that is associated with a key. |
HashFunc | Hashing function for CachedKey. The default is std::hash<CachedKey> . |
Usage example (see Analysis/UsedVarsVisitor):
class UsedVarsVisitor:
public Caching<ShPtr<Value>, ShPtr<UsedVars>,
HashFuncShPtr<Value>> {
};
ShPtr<UsedVars> UsedVarsVisitor::getUsedVars(ShPtr<Value> value) {
ShPtr<UsedVars> usedVars;
if (getCachedResult(value, usedVars)) {
return usedVars;
}
addToCache(value, usedVars);
return usedVars;
}
void enableCaching()
Enables caching.
Definition: caching.h:60
Caching(bool enableCaching)
Definition: caching.h:53
UsedVarsVisitor(bool visitSuccessors=true, bool visitNestedStmts=true, bool enableCaching=false)
Constructs a new visitor.
Definition: used_vars_visitor.cpp:180
template<typename CachedKey , typename CachedValue , typename HashFunc = std::hash<CachedKey>>
bool retdec::llvmir2hll::Caching< CachedKey, CachedValue, HashFunc >::getCachedResult |
( |
const CachedKey & |
key, |
|
|
CachedValue & |
value |
|
) |
| const |
|
inlineprotected |
If caching is enabled, stores the value associated with key into value.
- Returns
true
if there is a value associated to key, false
otherwise.
If there is a value associated with key, the value of value is left unchanged.
template<typename CachedKey , typename CachedValue , typename HashFunc = std::hash<CachedKey>>
Removes the value corresponding to the given key from the cache.
The key is removed as well. If there is no value corresponding to key, this function does nothing.