68template<
class KeyClass,
class ValueClass>
class Cache
106 mutable typename std::list<KeyClass>::const_iterator
_itKey;
114 mutable typename std::list<ValueClass>::const_iterator
_itValue;
170 bool shrink (
const KeyClass& key);
211 Cache (
const int maxEntries,
const int maxWeight);
265 bool hasKey (
const KeyClass& key)
const;
281 ValueClass
getValue (
const KeyClass& key)
const;
302 bool put (
const KeyClass& key,
const ValueClass& value);
Class Cache is a template-implementation of a cache with arbitrary classes for representing keys and ...
Cache()
A constructor for class Cache.
std::string toString() const
A method for providing a printable version of the represented cache, including all contained (key -->...
int getIndexInKey(const KeyClass &key) const
A method for providing the index of a given key in the vector _key.
int getNumberOfEntries() const
A method for retrieving the momentary number of (key --> value) pairs in the cache.
void print() const
A method for printing a string representation of the given cache to std::cout.
void clear()
Clears the cache so that it has no entry.
~Cache()
A destructor for class Cache.
std::list< int > _weights
container for the weights of all cached values
int getIndexInRank(const ValueClass &value) const
A method for providing the index of a given value in the vector _rank.
std::list< ValueClass > _value
_value captures the actual objects of interest; _value[i] corresponds to _key[i] and may be retrieve...
bool put(const KeyClass &key, const ValueClass &value)
Inserts the pair (key --> value) in the cache.
std::list< int > _rank
A bijection on the set {0, ..., _key.size() - 1}.
std::list< KeyClass >::const_iterator _itKey
a pointer to some element of _key; We make this mutable so that methods which leave the cache unmodif...
int getWeight() const
A method for retrieving the momentary weight of the cache.
std::list< ValueClass >::const_iterator _itValue
a pointer to some element of _value; We make this mutable so that methods which leave the cache unmod...
int _maxWeight
the bound on total cache weight; The cache will automatically ensure that this bound will never be e...
bool deleteLast(const KeyClass &key)
A method for deleting the least-ranked cache entry.
int _maxEntries
the bound for the number of cached key --> value pairs; The cache will automatically ensure that thi...
int getMaxWeight() const
A method for retrieving the maximum weight of the cache.
bool hasKey(const KeyClass &key) const
Checks whether the cache contains a pair (k --> v) such that k equals the given key.
bool shrink(const KeyClass &key)
A method for shrinking the given cache so that it meet the bounds on the maximum number of entries an...
std::list< KeyClass > _key
_key is sorted in ascending order, i.e., j < i ==> _key(j) < _key(i), where the right-hand side compa...
int _weight
for storing the momentary weight of the given cache; This is the sum of _value[i]....
int getMaxNumberOfEntries() const
A method for retrieving the maximum number of (key --> value) pairs in the cache.
ValueClass getValue(const KeyClass &key) const
Returns the value for a given key.