mCRL2
Loading...
Searching...
No Matches
mcrl2::utilities::fixed_size_cache< Policy > Class Template Reference

A cache keeps track of key-value pairs similar to a map. The difference is that a cache has (an optional) maximum size and a policy that determines what element gets evicted when the cache is full. More...

#include <fixed_size_cache.h>

Inheritance diagram for mcrl2::utilities::fixed_size_cache< Policy >:
mcrl2::utilities::function_cache< Policy, F, Args >

Public Types

using key_type = typename Policy::key_type
 
using iterator = typename Policy::map_type::iterator
 
using const_iterator = typename Policy::map_type::const_iterator
 

Public Member Functions

 fixed_size_cache (std::size_t max_size=1024)
 
const_iterator begin () const
 
const_iterator end () const
 
void clear ()
 
std::size_t count (const key_type &key) const
 
iterator find (const key_type &key)
 
template<typename ... Args>
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 element might be removed.
 

Protected Attributes

Policy::map_type m_map
 The underlying mapping from keys to their cached results.
 
Policy m_policy
 The replacement policy for keys in the cache.
 
std::size_t m_maximum_size
 The maximum number of elements to cache.
 

Detailed Description

template<typename Policy>
class mcrl2::utilities::fixed_size_cache< Policy >

A cache keeps track of key-value pairs similar to a map. The difference is that a cache has (an optional) maximum size and a policy that determines what element gets evicted when the cache is full.

Works with arbirary maps that implement the unordered_map interface.

Definition at line 26 of file fixed_size_cache.h.

Member Typedef Documentation

◆ const_iterator

template<typename Policy >
using mcrl2::utilities::fixed_size_cache< Policy >::const_iterator = typename Policy::map_type::const_iterator

Definition at line 31 of file fixed_size_cache.h.

◆ iterator

template<typename Policy >
using mcrl2::utilities::fixed_size_cache< Policy >::iterator = typename Policy::map_type::iterator

Definition at line 30 of file fixed_size_cache.h.

◆ key_type

template<typename Policy >
using mcrl2::utilities::fixed_size_cache< Policy >::key_type = typename Policy::key_type

Definition at line 29 of file fixed_size_cache.h.

Constructor & Destructor Documentation

◆ fixed_size_cache()

template<typename Policy >
mcrl2::utilities::fixed_size_cache< Policy >::fixed_size_cache ( std::size_t  max_size = 1024)
inlineexplicit

Definition at line 33 of file fixed_size_cache.h.

Member Function Documentation

◆ begin()

template<typename Policy >
const_iterator mcrl2::utilities::fixed_size_cache< Policy >::begin ( ) const
inline

Definition at line 48 of file fixed_size_cache.h.

◆ clear()

template<typename Policy >
void mcrl2::utilities::fixed_size_cache< Policy >::clear ( )
inline

Definition at line 51 of file fixed_size_cache.h.

◆ count()

template<typename Policy >
std::size_t mcrl2::utilities::fixed_size_cache< Policy >::count ( const key_type key) const
inline

Definition at line 53 of file fixed_size_cache.h.

◆ emplace()

template<typename Policy >
template<typename ... Args>
std::pair< iterator, bool > mcrl2::utilities::fixed_size_cache< Policy >::emplace ( Args &&...  args)
inline

Stores the given key-value pair in the cache. Depending on the cache policy and capacity an existing element might be removed.

Definition at line 63 of file fixed_size_cache.h.

◆ end()

template<typename Policy >
const_iterator mcrl2::utilities::fixed_size_cache< Policy >::end ( ) const
inline

Definition at line 49 of file fixed_size_cache.h.

◆ find()

template<typename Policy >
iterator mcrl2::utilities::fixed_size_cache< Policy >::find ( const key_type key)
inline

Definition at line 55 of file fixed_size_cache.h.

Member Data Documentation

◆ m_map

template<typename Policy >
Policy::map_type mcrl2::utilities::fixed_size_cache< Policy >::m_map
protected

The underlying mapping from keys to their cached results.

Definition at line 89 of file fixed_size_cache.h.

◆ m_maximum_size

template<typename Policy >
std::size_t mcrl2::utilities::fixed_size_cache< Policy >::m_maximum_size
protected

The maximum number of elements to cache.

Definition at line 92 of file fixed_size_cache.h.

◆ m_policy

template<typename Policy >
Policy mcrl2::utilities::fixed_size_cache< Policy >::m_policy
protected

The replacement policy for keys in the cache.

Definition at line 90 of file fixed_size_cache.h.


The documentation for this class was generated from the following file: