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 );
207 for (
auto it =
myMap.begin(), itE =
myMap.end(); it != itE; )
208 if ( it->second.second <= threshold )
210 it =
myMap.erase( it );
228 out <<
"[TimeStampMemoizer " <<
myMap.size() <<
"/" <<
myMaxSize <<
" items"
252 std::unordered_map< Key, StoredValue >
myMap;
281 template <
typename TKey,
typename TValue>
286 object.selfDisplay( out );
301#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)