4 #include <unordered_map>
6 #if __cplusplus > 199711L || _MSC_VER >= 1800
29 typedef typename std::list<T>::iterator ListIterator;
30 typedef typename std::unordered_map<T, ListIterator>::iterator MapIterator;
53 int put(
const T& element, T* deletedValue =
nullptr)
55 m_CacheItemsList.push_front(element);
59 std::pair<MapIterator, bool> pair =
60 m_CacheItemsMap.insert(std::make_pair(element, m_CacheItemsList.begin()));
61 if (pair.second ==
false)
63 m_CacheItemsList.erase(pair.first->second);
64 pair.first->second = m_CacheItemsList.begin();
67 if (m_CacheItemsMap.size() > m_MaxSize)
69 ListIterator lruIter = m_CacheItemsList.end();
72 if (deletedValue !=
nullptr)
73 #if __cplusplus > 199711L || _MSC_VER >= 1800
74 *deletedValue = std::move(*lruIter);
76 *deletedValue = *lruIter;
78 m_CacheItemsMap.erase(*lruIter);
79 m_CacheItemsList.erase(lruIter);
92 return m_CacheItemsList.front();
101 return m_CacheItemsList.back();
110 MapIterator iter = m_CacheItemsMap.find(element);
111 if (iter == m_CacheItemsMap.end())
114 m_CacheItemsList.erase(iter->second);
115 m_CacheItemsMap.erase(iter);
131 return m_CacheItemsMap.size();
135 std::list<T> m_CacheItemsList;
136 std::unordered_map<T, ListIterator> m_CacheItemsMap;
LRUList(size_t maxSize)
Definition: LRUList.h:36
size_t getMaxSize() const
Definition: LRUList.h:121
const T & getLRUElement() const
Definition: LRUList.h:99
int put(const T &element, T *deletedValue=nullptr)
Definition: LRUList.h:53
const T & getMRUElement() const
Definition: LRUList.h:90
void eraseElement(const T &element)
Definition: LRUList.h:108
size_t getSize() const
Definition: LRUList.h:129
The main namespace for the PcapPlusPlus lib.