ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Utils::Cache< Key, Value > Class Template Reference

#include <Cache.hpp>

Public Types

using key_type = Key
 
using value_type = const Value *
 
using size_type = typename map_type::size_type
 

Public Member Functions

 Cache ()
 
 Cache (size_type max_size)
 
void invalidate ()
 Clear the cache.
 
bool has (Key const &k) const
 Query if k is contained in the cache.
 
size_type size () const
 Number of elements currently cached.
 
size_type max_size () const
 Maximal size of the cache.
 
template<typename ValueRef >
Value const * put (Key const &k, ValueRef &&v)
 Put a value into the cache.
 
template<typename KeyInputIterator , typename ValueInputIterator >
KeyInputIterator put (KeyInputIterator kbegin, KeyInputIterator kend, ValueInputIterator vbegin)
 Put a range of values into the cache.
 
Value const * get (Key const &k) const
 Get a value.
 

Detailed Description

template<typename Key, typename Value>
class Utils::Cache< Key, Value >

Definition at line 29 of file Cache.hpp.

Member Typedef Documentation

◆ key_type

template<typename Key , typename Value >
using Utils::Cache< Key, Value >::key_type = Key

Definition at line 34 of file Cache.hpp.

◆ size_type

template<typename Key , typename Value >
using Utils::Cache< Key, Value >::size_type = typename map_type::size_type

Definition at line 36 of file Cache.hpp.

◆ value_type

template<typename Key , typename Value >
using Utils::Cache< Key, Value >::value_type = const Value *

Definition at line 35 of file Cache.hpp.

Constructor & Destructor Documentation

◆ Cache() [1/2]

template<typename Key , typename Value >
Utils::Cache< Key, Value >::Cache ( )
inline

Definition at line 38 of file Cache.hpp.

◆ Cache() [2/2]

template<typename Key , typename Value >
Utils::Cache< Key, Value >::Cache ( size_type  max_size)
inlineexplicit

Definition at line 42 of file Cache.hpp.

Member Function Documentation

◆ get()

template<typename Key , typename Value >
Value const * Utils::Cache< Key, Value >::get ( Key const &  k) const
inline

Get a value.

The value is owned by the cache and can not be modified. Pointers into the cache can be invalidated at any point and should not be stored beyond the calling function.

Definition at line 174 of file Cache.hpp.

◆ has()

template<typename Key , typename Value >
bool Utils::Cache< Key, Value >::has ( Key const &  k) const
inline

Query if k is contained in the cache.

Definition at line 98 of file Cache.hpp.

Referenced by Utils::Cache< Key, Value >::put().

◆ invalidate()

template<typename Key , typename Value >
void Utils::Cache< Key, Value >::invalidate ( )
inline

Clear the cache.

This invalidates all pointers into the cache.

Definition at line 95 of file Cache.hpp.

◆ max_size()

template<typename Key , typename Value >
size_type Utils::Cache< Key, Value >::max_size ( ) const
inline

Maximal size of the cache.

Definition at line 104 of file Cache.hpp.

Referenced by Utils::Cache< Key, Value >::put().

◆ put() [1/2]

template<typename Key , typename Value >
template<typename ValueRef >
Value const * Utils::Cache< Key, Value >::put ( Key const &  k,
ValueRef &&  v 
)
inline

Put a value into the cache.

If the value already exists, it is overwritten. When the size of the cache would grow below the maximal size, a random element is removed before putting the new one.

Definition at line 112 of file Cache.hpp.

References Utils::Cache< Key, Value >::has().

Referenced by Utils::Cache< Key, Value >::put().

◆ put() [2/2]

template<typename Key , typename Value >
template<typename KeyInputIterator , typename ValueInputIterator >
KeyInputIterator Utils::Cache< Key, Value >::put ( KeyInputIterator  kbegin,
KeyInputIterator  kend,
ValueInputIterator  vbegin 
)
inline

Put a range of values into the cache.

If the values already exists, it is overwritten. When the size of the cache would grow below the maximal size, a random elements are removed until all of the new values fit. If the given range is larger than max_size(), only the first max_size() elements are put into the cache.

Template Parameters
KeyInputIteratoriterator of keys, at least InputIterator.
ValueInputIteratoriterator of value, at least InputIterator.
Returns
KeyInputIterator one past the last element that was put into the cache.

Definition at line 149 of file Cache.hpp.

References Utils::Cache< Key, Value >::max_size(), Utils::Cache< Key, Value >::put(), and Utils::Cache< Key, Value >::size().

◆ size()

template<typename Key , typename Value >
size_type Utils::Cache< Key, Value >::size ( ) const
inline

Number of elements currently cached.

Definition at line 101 of file Cache.hpp.

Referenced by Utils::Cache< Key, Value >::put().


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