Slicer  4.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
List of all members | Classes | Public Member Functions
itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType > Class Template Reference

#include <Libs/vtkITK/itkTimeSeriesDatabaseHelper.h>

Inheritance diagram for itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >:
Inheritance graph
[legend]

Public Member Functions

void clear ()
 
void debug_dump (ostream &ostr=cerr)
 
bool empty ()
 
ValueType * find (const KeyType &key)
 
string format_str (const char *format,...) const
 NDEBUG. More...
 
unsigned get_maxsize ()
 
void insert (const KeyType &key, const ValueType &value)
 
 LRUCache (unsigned maxsize_=100)
 
void set_maxsize (unsigned maxsize_)
 
size_t size ()
 
void statistics (ostream &ostr=cerr) const
 
 ~LRUCache ()
 

Detailed Description

template<typename KeyType, typename ValueType>
class itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >

A cache class.

Stores cached values for keys. Yseful when the value is a result of some complex calculation on key that we want to avoid doing repeatedly.

The basic interface is insert() for insertions and find() to look up items. key_type must have operator < defined.

Has a maximal size (amount of elements - key/value pairs) and employs a LRU (Least Recently Used) removal policy when that maximum is exceeded, meaning that the item which was accesses least recently is removed.

The class also keeps statistics, cache hit/miss rate that may be useful while debugging. The statistics counting works only if NDEBUG is not defined.

Definition at line 102 of file itkTimeSeriesDatabaseHelper.h.

Constructor & Destructor Documentation

◆ LRUCache()

template<typename KeyType, typename ValueType>
itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::LRUCache ( unsigned  maxsize_ = 100)
inline

Create a new cache.

Parameters
maxsize_maximal size of the cache

Definition at line 109 of file itkTimeSeriesDatabaseHelper.h.

◆ ~LRUCache()

template<typename KeyType, typename ValueType>
itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::~LRUCache ( )
inline

Definition at line 122 of file itkTimeSeriesDatabaseHelper.h.

Member Function Documentation

◆ clear()

template<typename KeyType, typename ValueType>
void itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::clear ( )
inline

Clear the cache.

Definition at line 143 of file itkTimeSeriesDatabaseHelper.h.

◆ debug_dump()

template<typename KeyType, typename ValueType>
void itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::debug_dump ( ostream &  ostr = cerr)
inline

Dumps the cache to output.

Useful for debugging. Expects key/value types to have an output operator (<<) defined.

Definition at line 225 of file itkTimeSeriesDatabaseHelper.h.

◆ empty()

template<typename KeyType, typename ValueType>
bool itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::empty ( )
inline

Is the cache empty ?

Definition at line 136 of file itkTimeSeriesDatabaseHelper.h.

◆ find()

template<typename KeyType, typename ValueType>
ValueType* itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::find ( const KeyType &  key)
inline

Looks for a key in the cache.

Returns a pointer to the value if found, 0 otherwise.

Warning: a bare pointer is returned, at the user's risk. The pointer may become invalid at some time, so it should be used immediately.

An access moves the element to the front of the list (marking it MRU).

Definition at line 200 of file itkTimeSeriesDatabaseHelper.h.

◆ format_str()

template<typename KeyType, typename ValueType>
string itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::format_str ( const char *  format,
  ... 
) const
inline

NDEBUG.

Works like sprintf, but returns the resulting string in a memory-safe manner.

Definition at line 275 of file itkTimeSeriesDatabaseHelper.h.

◆ get_maxsize()

template<typename KeyType, typename ValueType>
unsigned itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::get_maxsize ( )
inline

Definition at line 118 of file itkTimeSeriesDatabaseHelper.h.

◆ insert()

template<typename KeyType, typename ValueType>
void itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::insert ( const KeyType &  key,
const ValueType &  value 
)
inline

Inserts a key/value pair to the cache.

Is the key already in the cache ? Note: find() is used intentionally - if an element gets updated, it should be moved to be MRU.

Found ?

Update the value.

Add it to the table and to the front of the list (mark it MRU).

If the maximal size was exceeded, clean up LRU element.

Definition at line 152 of file itkTimeSeriesDatabaseHelper.h.

◆ set_maxsize()

template<typename KeyType, typename ValueType>
void itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::set_maxsize ( unsigned  maxsize_)
inline

Definition at line 114 of file itkTimeSeriesDatabaseHelper.h.

◆ size()

template<typename KeyType, typename ValueType>
size_t itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::size ( )
inline

How many elements are currently stored in the cache ?

Definition at line 129 of file itkTimeSeriesDatabaseHelper.h.

◆ statistics()

template<typename KeyType, typename ValueType>
void itk::TimeSeriesDatabaseHelper::LRUCache< KeyType, ValueType >::statistics ( ostream &  ostr = cerr) const
inline

Prints cache statistics.

Only in debug mode (NDEBUG not defined).

Definition at line 255 of file itkTimeSeriesDatabaseHelper.h.


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