10#ifndef MCRL2_UTILITIES_FIXED_SIZE_CACHE_H
11#define MCRL2_UTILITIES_FIXED_SIZE_CACHE_H
25template<
typename Policy>
30 using iterator =
typename Policy::map_type::iterator;
57 return m_map.find(key);
62 template<
typename ...Args>
63 std::pair<iterator, bool>
emplace(Args&&... args)
68 auto result =
find(args...);
69 if (result ==
m_map.end())
79 auto emplace_result =
m_map.emplace(std::forward<Args>(args)...);
80 m_policy.inserted((*emplace_result.first).first);
81 return emplace_result;
85 return std::make_pair(result,
false);
89 typename Policy::map_type
m_map;
99template<
typename Policy,
typename F,
typename ...Args>
117 auto operator()(Args... args) ->
typename std::invoke_result_t<F, Args...>
122 auto result =
find(args...);
123 if (result ==
m_map.end())
135 m_policy.inserted((*emplace_result.first).first);
136 return emplace_result.first->second;
140 return result->second;
148template<
typename Key,
typename T>
151template<
typename F,
typename Args>
A cache keeps track of key-value pairs similar to a map. The difference is that a cache has (an optio...
const_iterator begin() const
typename Policy::key_type key_type
iterator find(const key_type &key)
std::size_t count(const key_type &key) const
const_iterator end() const
Policy::map_type m_map
The underlying mapping from keys to their cached results.
std::pair< iterator, bool > emplace(Args &&... args)
Stores the given key-value pair in the cache. Depending on the cache policy and capacity an existing ...
Policy m_policy
The replacement policy for keys in the cache.
typename Policy::map_type::const_iterator const_iterator
typename Policy::map_type::iterator iterator
fixed_size_cache(std::size_t max_size=1024)
std::size_t m_maximum_size
The maximum number of elements to cache.
A cache keeps track of key-value pairs similar to a map. The difference is that a cache has (an optio...
iterator find(const key_type &key)
auto operator()(Args... args) -> typename std::invoke_result_t< F, Args... >
Stores the given key-value pair in the cache. Depending on the cache policy and capacity an existing ...
F m_cached_function
The function of which the results are cached.
Policy::map_type m_map
The underlying mapping from keys to their cached results.
function_cache(F cached_function=F(), std::size_t max_size=1024)
Policy m_policy
The replacement policy for keys in the cache.
std::size_t m_maximum_size
The maximum number of elements to cache.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...