C++Memo  1.0-RC
Generic framework for memoization, providing automatic parallelization.
 All Classes Files Functions
Classes | Public Member Functions | List of all members
cppmemo::CppMemo< Key, Value, KeyHash1, KeyHash2, KeyEqual > Class Template Reference

This class implements a generic framework for memoization supporting automatic parallel execution. More...

#include <cppmemo.hpp>

Classes

class  PrerequisitesGatherer
 The function object gathering prerequisites from the DeclarePrerequisites function passed to an appropriate CppMemo::getValue() overload. More...
 
class  PrerequisitesProvider
 The function object providing prerequisites to the Compute function passed to an appropriate CppMemo::getValue() overload. More...
 

Public Member Functions

 CppMemo (int defaultNumThreads=1, std::size_t estimatedNumEntries=0, bool detectCircularDependencies=false)
 Constructor. More...
 
int getDefaultNumThreads () const
 Returns the default number of threads to be started.
 
void setDefaultNumThreads (int defaultNumThreads)
 Sets the default number of threads to be started.
 
bool getDetectCircularDependencies () const
 Returns true if circular dependency detection is enabled, false otherwise.
 
void setDetectCircularDependencies (bool detectCircularDependencies)
 Enables or disables circular dependency detection. More...
 
template<typename Compute , typename DeclarePrerequisites >
const Value & getValue (const Key &key, Compute compute, DeclarePrerequisites declarePrerequisites, int numThreads)
 Returns the value corresponding to the requested key, computing (and memoizing) it as needed. More...
 
template<typename Compute , typename DeclarePrerequisites >
const Value & getValue (const Key &key, Compute compute, DeclarePrerequisites declarePrerequisites)
 Returns the value corresponding to the requested key, computing (and memoizing) it as needed. More...
 
template<typename Compute >
const Value & getValue (const Key &key, Compute compute, int numThreads)
 Returns the value corresponding to the requested key, computing (and memoizing) it as needed. More...
 
template<typename Compute >
const Value & getValue (const Key &key, Compute compute)
 Returns the value corresponding to the requested key, computing (and memoizing) it as needed. More...
 
const Value & getValue (const Key &key) const
 Returns the memoized value corresponding to the requested key. If no value is memoized, a std::logic_error exception is thrown. More...
 
template<typename Compute , typename DeclarePrerequisites >
const Value & operator() (const Key &key, Compute compute, DeclarePrerequisites declarePrerequisites, int numThreads)
 Alias for getValue(const Key&, Compute, DeclarePrerequisites, int)
 
template<typename Compute , typename DeclarePrerequisites >
const Value & operator() (const Key &key, Compute compute, DeclarePrerequisites declarePrerequisites)
 Alias for getValue(const Key&, Compute, DeclarePrerequisites)
 
template<typename Compute >
const Value & operator() (const Key &key, Compute compute, int numThreads)
 Alias for getValue(const Key&, Compute, int)
 
template<typename Compute >
const Value & operator() (const Key &key, Compute compute)
 Alias for getValue(const Key&, Compute)
 
const Value & operator() (const Key &key) const
 Alias for getValue(const Key&)
 
 CppMemo (const CppMemo &)=delete
 
 CppMemo (CppMemo &&)=delete
 

Detailed Description

template<typename Key, typename Value, typename KeyHash1 = std::hash<Key>, typename KeyHash2 = fcmm::DefaultKeyHash2<Key>, typename KeyEqual = std::equal_to<Key>>
class cppmemo::CppMemo< Key, Value, KeyHash1, KeyHash2, KeyEqual >

This class implements a generic framework for memoization supporting automatic parallel execution.

Please read the documentation on the project website: http://projects.giacomodrago.com/c++memo

Template Parameters
Keythe type of the key (default-constructible and copy-constructible)
Valuethe type of the value (default-constructible and copy-constructible)
KeyHash1the type of a function object that calculates the hash of the key; it should have the same interface as std::hash<T>
KeyHash2the type of another function object that calculates the hash of the key: it should be completely independent from KeyHash1; the default for this template parameter is only available for integral types.
KeyEqualthe type of the function object that checks the equality of the two keys; it should have the same interface as std::equal_to<T>

Constructor & Destructor Documentation

template<typename Key , typename Value , typename KeyHash1 = std::hash<Key>, typename KeyHash2 = fcmm::DefaultKeyHash2<Key>, typename KeyEqual = std::equal_to<Key>>
cppmemo::CppMemo< Key, Value, KeyHash1, KeyHash2, KeyEqual >::CppMemo ( int  defaultNumThreads = 1,
std::size_t  estimatedNumEntries = 0,
bool  detectCircularDependencies = false 
)
inline

Constructor.

Parameters
defaultNumThreadsthe default number of threads to be started
estimatedNumEntriesan estimate for the number of memoized entries that will be stored in this class instance
detectCircularDependenciesenable circular dependency detection

Member Function Documentation

template<typename Key , typename Value , typename KeyHash1 = std::hash<Key>, typename KeyHash2 = fcmm::DefaultKeyHash2<Key>, typename KeyEqual = std::equal_to<Key>>
template<typename Compute , typename DeclarePrerequisites >
const Value& cppmemo::CppMemo< Key, Value, KeyHash1, KeyHash2, KeyEqual >::getValue ( const Key &  key,
Compute  compute,
DeclarePrerequisites  declarePrerequisites,
int  numThreads 
)
inline

Returns the value corresponding to the requested key, computing (and memoizing) it as needed.

Parameters
keythe requested key
computea function or functor used to compute the value corresponding to a given key
declarePrerequisitesa function or functor used to gather the prerequisites of a given key
numThreadsthe number of threads to be started
Template Parameters
Computefunction or functor implementing Value operator()(const Key&, CppMemo<Key, Value, KeyHash1, KeyHash2, KeyEqual>::PrerequisitesProvider)
DeclarePrerequisitesfunction or functor implementing void operator()(const Key&, CppMemo<Key, Value, KeyHash1, KeyHash2, KeyEqual>::PrerequisitesGatherer)
Returns
the value corresponding to the requested key
template<typename Key , typename Value , typename KeyHash1 = std::hash<Key>, typename KeyHash2 = fcmm::DefaultKeyHash2<Key>, typename KeyEqual = std::equal_to<Key>>
template<typename Compute , typename DeclarePrerequisites >
const Value& cppmemo::CppMemo< Key, Value, KeyHash1, KeyHash2, KeyEqual >::getValue ( const Key &  key,
Compute  compute,
DeclarePrerequisites  declarePrerequisites 
)
inline

Returns the value corresponding to the requested key, computing (and memoizing) it as needed.

The default number of threads will be started (see setDefaultNumThreads()).

Parameters
keythe requested key
computea function or functor used to compute the value corresponding to a given key
declarePrerequisitesa function or functor used to gather the prerequisites of a given key
Template Parameters
Computefunction or functor implementing Value operator()(const Key&, CppMemo<Key, Value, KeyHash1, KeyHash2, KeyEqual>::PrerequisitesProvider)
DeclarePrerequisitesfunction or functor implementing void operator()(const Key&, CppMemo<Key, Value, KeyHash1, KeyHash2, KeyEqual>::PrerequisitesGatherer)
Returns
the value corresponding to the requested key
template<typename Key , typename Value , typename KeyHash1 = std::hash<Key>, typename KeyHash2 = fcmm::DefaultKeyHash2<Key>, typename KeyEqual = std::equal_to<Key>>
template<typename Compute >
const Value& cppmemo::CppMemo< Key, Value, KeyHash1, KeyHash2, KeyEqual >::getValue ( const Key &  key,
Compute  compute,
int  numThreads 
)
inline

Returns the value corresponding to the requested key, computing (and memoizing) it as needed.

Important note. This overload omits the DeclarePrerequisites parameter: the prerequisites of a given key are gathered indirectly by dry running the Compute function. Please read the relevant documentation on the project website.

Parameters
keythe requested key
computea function or functor used to compute the value corresponding to a given key
numThreadsthe number of threads to be started
Template Parameters
Computefunction or functor implementing Value operator()(const Key&, CppMemo<Key, Value, KeyHash1, KeyHash2, KeyEqual>::PrerequisitesProvider)
Returns
the value corresponding to the requested key
template<typename Key , typename Value , typename KeyHash1 = std::hash<Key>, typename KeyHash2 = fcmm::DefaultKeyHash2<Key>, typename KeyEqual = std::equal_to<Key>>
template<typename Compute >
const Value& cppmemo::CppMemo< Key, Value, KeyHash1, KeyHash2, KeyEqual >::getValue ( const Key &  key,
Compute  compute 
)
inline

Returns the value corresponding to the requested key, computing (and memoizing) it as needed.

The default number of threads will be started (see setDefaultNumThreads()).

Important note. This overload omits the DeclarePrerequisites parameter: the prerequisites of a given key are gathered indirectly by dry running the Compute function. Please read the relevant documentation on the project website.

Parameters
keythe requested key
computea function or functor used to compute the value corresponding to a given key
Template Parameters
Computefunction or functor implementing Value operator()(const Key&, CppMemo<Key, Value, KeyHash1, KeyHash2, KeyEqual>::PrerequisitesProvider)
Returns
the value corresponding to the requested key
template<typename Key , typename Value , typename KeyHash1 = std::hash<Key>, typename KeyHash2 = fcmm::DefaultKeyHash2<Key>, typename KeyEqual = std::equal_to<Key>>
const Value& cppmemo::CppMemo< Key, Value, KeyHash1, KeyHash2, KeyEqual >::getValue ( const Key &  key) const
inline

Returns the memoized value corresponding to the requested key. If no value is memoized, a std::logic_error exception is thrown.

Parameters
keythe requested key
Returns
the memoized value corresponding to the requested key
Exceptions
std::logic_errorthrown if no value for the requested key is memoized
template<typename Key , typename Value , typename KeyHash1 = std::hash<Key>, typename KeyHash2 = fcmm::DefaultKeyHash2<Key>, typename KeyEqual = std::equal_to<Key>>
void cppmemo::CppMemo< Key, Value, KeyHash1, KeyHash2, KeyEqual >::setDetectCircularDependencies ( bool  detectCircularDependencies)
inline

Enables or disables circular dependency detection.

Parameters
detectCircularDependenciestrue to enable circular dependency detection, false to disable it

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