5 #include <unordered_map>
7 #if __cplusplus > 199711L || _MSC_VER >= 1800
26 typedef typename std::list<T>::iterator ListIterator;
27 typedef typename std::unordered_map<T, ListIterator>::iterator MapIterator;
46 int put(
const T& element, T* deletedValue =
nullptr)
48 m_CacheItemsList.push_front(element);
52 std::pair<MapIterator, bool> pair =
53 m_CacheItemsMap.insert(std::make_pair(element, m_CacheItemsList.begin()));
54 if (pair.second ==
false)
56 m_CacheItemsList.erase(pair.first->second);
57 pair.first->second = m_CacheItemsList.begin();
60 if (m_CacheItemsMap.size() > m_MaxSize)
62 ListIterator lruIter = m_CacheItemsList.end();
65 if (deletedValue !=
nullptr)
66 #if __cplusplus > 199711L || _MSC_VER >= 1800
67 *deletedValue = std::move(*lruIter);
69 *deletedValue = *lruIter;
71 m_CacheItemsMap.erase(*lruIter);
72 m_CacheItemsList.erase(lruIter);
83 return m_CacheItemsList.front();
90 return m_CacheItemsList.back();
97 MapIterator iter = m_CacheItemsMap.find(element);
98 if (iter == m_CacheItemsMap.end())
101 m_CacheItemsList.erase(iter->second);
102 m_CacheItemsMap.erase(iter);
114 return m_CacheItemsMap.size();
118 std::list<T> m_CacheItemsList;
119 std::unordered_map<T, ListIterator> m_CacheItemsMap;
size_t getMaxSize() const
Definition: LRUList.h:106
const T & getLRUElement() const
Definition: LRUList.h:88
int put(const T &element, T *deletedValue=nullptr)
Definition: LRUList.h:46
const T & getMRUElement() const
Definition: LRUList.h:81
void eraseElement(const T &element)
Definition: LRUList.h:95
LRUList(std::size_t maxSize)
Definition: LRUList.h:31
size_t getSize() const
Definition: LRUList.h:112
The main namespace for the PcapPlusPlus lib.