 |
Belle II Software
release-05-01-25
|
13 #include <boost/multi_index_container.hpp>
14 #include <boost/multi_index/sequenced_index.hpp>
15 #include <boost/multi_index/hashed_index.hpp>
16 #include <boost/multi_index/member.hpp>
50 template <
class KEY,
class VALUE>
class MRUCache {
55 typedef boost::multi_index_container <
57 boost::multi_index::indexed_by <
58 boost::multi_index::sequenced<>,
59 boost::multi_index::hashed_unique <
60 boost::multi_index::member<value_type, KEY, &value_type::first>
65 typedef typename container_type::const_iterator
iterator;
67 typedef typename container_type::template nth_index<1>::type::const_iterator
hash_iterator;
90 std::pair<iterator, bool> p =
m_container.push_front(item);
106 bool retrieve(
const KEY& key, VALUE& value)
container_type m_container
Container for the items.
std::pair< KEY, VALUE > value_type
type of elements stored in the cache
void update(const iterator &item)
Update an item, thus marking it as recently accessed and putting it to the front of the list.
void setMaxSize(size_t maxSize)
Set maximum number of cache entries.
bool retrieve(const KEY &key, VALUE &value)
Retrieve a value from the cache if it exists.
unsigned int getHits() const
Get number of cache hits since creation/last clear.
MRUCache(size_t maxSize)
Constructor setting the maximum number of cached items.
iterator begin() const
Return iterator to the begin of the cache.
unsigned int getMisses() const
Get number of cache misses since creation/last clear.
size_t getMaxSize() const
Get maximum number of cache entries.
container_type::const_iterator iterator
iterator over all cached items, sorted by access: most recent used first
Abstract base class for different kinds of events.
boost::multi_index_container< value_type, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::hashed_unique< boost::multi_index::member< value_type, KEY, &value_type::first > > > > container_type
type of container for the elements
unsigned int m_overflows
Number of overflows.
void insert(const KEY &key, const VALUE &value)
Insert a key value pair into the cache.
unsigned int m_misses
Number of misses.
unsigned int m_hits
Number of hits.
iterator end() const
Return iterator to the end of the cache.
unsigned int getOverflows() const
Get number of overflows (dropped items) since creation/last clear.
size_t size() const
Return actual size of the cache.
size_t m_maxSize
Maximum size of the cache.
container_type::template nth_index< 1 >::type::const_iterator hash_iterator
iterator over the hash index to the items