1 #ifndef PCAPPP_LRU_LIST 2 #define PCAPPP_LRU_LIST 28 typedef typename std::list<T>::iterator ListIterator;
29 typedef typename std::map<T, ListIterator>::iterator MapIterator;
49 T*
put(
const T& element)
51 m_CacheItemsList.push_front(element);
52 MapIterator iter = m_CacheItemsMap.find(element);
53 if (iter != m_CacheItemsMap.end())
54 m_CacheItemsList.erase(iter->second);
55 m_CacheItemsMap[element] = m_CacheItemsList.begin();
57 if (m_CacheItemsList.size() > m_MaxSize)
59 ListIterator lruIter = m_CacheItemsList.end();
61 T* deletedValue =
new T(*lruIter);
62 m_CacheItemsMap.erase(*lruIter);
63 m_CacheItemsList.erase(lruIter);
77 return m_CacheItemsList.front();
86 return m_CacheItemsList.back();
95 MapIterator iter = m_CacheItemsMap.find(element);
96 if (iter == m_CacheItemsMap.end())
99 m_CacheItemsList.erase(iter->second);
100 m_CacheItemsMap.erase(element);
111 inline size_t getSize() {
return m_CacheItemsMap.size(); }
114 std::list<T> m_CacheItemsList;
115 std::map<T, ListIterator> m_CacheItemsMap;
const T & getLRUElement()
Definition: LRUList.h:84
size_t getMaxSize()
Definition: LRUList.h:106
const T & getMRUElement()
Definition: LRUList.h:75
void eraseElement(const T &element)
Definition: LRUList.h:93
LRUList(size_t maxSize)
Definition: LRUList.h:35
T * put(const T &element)
Definition: LRUList.h:49
The main namespace for the PcapPlusPlus lib.
size_t getSize()
Definition: LRUList.h:111