AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
ConcurrentCache< Key, Data, Policy, Container > Class Template Reference

The class template ConcurrentCache describes an associative static container that allows the concurrent access to the stored data. More...

Inherits Policy< Container >.

Public Member Functions

template<class F , class... Args>
data_type const & get (key_type const &key, F &&f, Args &&... args) const
 Return the data associated to the key. More...
 

Detailed Description

template<class Key, class Data, template< class > class Policy, class Container>
class AMDiS::ConcurrentCache< Key, Data, Policy, Container >

The class template ConcurrentCache describes an associative static container that allows the concurrent access to the stored data.

Cache data of arbitray type that needs initialization on the first access. The data is thereby initialized thread-wise or globally only once, and guarantees that you always get initialized data.

Template Parameters
KeyThe type of key to access the data.
DataThe type of the data stored in the cache. The behaviur is undefined if Data is not the same type as Container::mapped_type.
PolicyA policy class template implementing the method get_or_init(). Three implementations are provided: ConsecutivePolicy, ThreadLocalPolicy and StaticLockedPolicy. By default, if no policy class template is specified, the ThreadLocalPolicy is used.
See also
ConcurrentCachePolicy
Template Parameters
ContainerThe type of the underlying associative container to use to store the data. The container must satisfy the requirements of AssociativeContainer. The standard containers std::map and std::unordered_map satisfie this requirement. By default, if not container class is specified, the standard container std::unordered_map<Key,Data> is used. Note, an unordered_map requires the key to be hashable.

The Policy class template is a template parametrizable with the container type, that provides a static get_or_init() method that is called with the key, and a functor for creation of new data elements.

Member Function Documentation

◆ get()

data_type const & get ( key_type const &  key,
F &&  f,
Args &&...  args 
) const
inline

Return the data associated to the key.

Return the data associated to key. If no data is found, create a new entry in the container with a value obtained from the functor, by calling f(key, args...).

Parameters
fA functor of signature data_type(key_type, Args...)
args...Arguments passed additionally to the functor f

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