31#if defined(TimeStampMemoizer_RECURSES)
32#error Recursive header files inclusion detected in TimeStampMemoizer.h
35#define TimeStampMemoizer_RECURSES
37#if !defined TimeStampMemoizer_h
39#define TimeStampMemoizer_h
44#include <unordered_map>
45#include "DGtal/base/Common.h"
73 template <
typename TKey,
typename TValue>
99 bool verbose =
false )
163 const std::unordered_map< Key, StoredValue > &
map()
const
175 std::pair< Value, bool >
get(
const Key& key )
177 auto it =
myMap.find( key );
178 if ( it ==
myMap.end() )
179 return std::make_pair(
Value(),
false );
182 return std::make_pair( it->second.first,
false );
206 for (
auto it =
myMap.begin(), itE =
myMap.end(); it != itE; )
207 if ( it->second.second <= threshold )
209 it =
myMap.erase( it );
227 out <<
"[TimeStampMemoizer " <<
myMap.size() <<
"/" <<
myMaxSize <<
" items"
251 std::unordered_map< Key, StoredValue >
myMap;
280 template <
typename TKey,
typename TValue>
285 object.selfDisplay( out );
300#undef TimeStampMemoizer_RECURSES
Aim: A generic class to store a given maximum number of pairs (key, value). The class tends to memori...
std::unordered_map< Key, StoredValue > myMap
The map memoizing computations.
std::pair< Value, bool > get(const Key &key)
TimeStampMemoizer & operator=(TimeStampMemoizer &&other)=default
TimeStampMemoizer & operator=(const TimeStampMemoizer &other)=default
const std::unordered_map< Key, StoredValue > & map() const
DGtal::uint32_t TimeStamp
TimeStampMemoizer(const TimeStampMemoizer &other)=default
void cleanUp()
Clean-up the memoizer by removing a fraction of its oldest elements.
TimeStampMemoizer(Size max_size=0, double ratio=0.5, bool verbose=false)
Size myHits
The number of hits since the last clean-up.
void selfDisplay(std::ostream &out) const
TimeStamp myTimeStamp
Current time.
~TimeStampMemoizer()=default
TimeStampMemoizer(TimeStampMemoizer &&other)=default
Size myMaxSize
The maximal number of memoized items.
void set(const Key &key, const Value &value)
bool myVerbose
when 'true', traces some information.
std::pair< Value, TimeStamp > StoredValue
double myRatio
The minimal ratio to remove if the maximal number of items is reached.
TimeStampMemoizer< TKey, TValue > Self
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::uint32_t uint32_t
unsigned 32-bit integer.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)