LibreOffice Module o3tl (master) 1
|
LRU map. More...
#include <lru_map.hxx>
Public Types | |
typedef std::pair< Key, Value > | key_value_pair_t |
typedef list_iterator_t | iterator |
typedef list_const_iterator_t | const_iterator |
Public Member Functions | |
lru_map (size_t nMaxSize) | |
~lru_map () | |
void | setMaxSize (size_t nMaxSize) |
void | insert (key_value_pair_t &rPair) |
void | insert (key_value_pair_t &&rPair) |
list_const_iterator_t | find (const Key &key) |
template<class UnaryPredicate > | |
void | remove_if (UnaryPredicate pred) |
list_const_iterator_t | begin () const |
list_const_iterator_t | end () const |
size_t | size () const |
void | clear () |
Private Types | |
typedef std::list< key_value_pair_t > | list_t |
typedef list_t::iterator | list_iterator_t |
typedef list_t::const_iterator | list_const_iterator_t |
typedef std::unordered_map< Key, list_iterator_t, KeyHash, KeyEqual > | map_t |
typedef map_t::iterator | map_iterator_t |
typedef map_t::const_iterator | map_const_iterator_t |
Private Member Functions | |
void | addSize (const Value &value) |
void | removeSize (const Value &value) |
void | removeOldestItem () |
void | checkLRUItemInsert () |
void | checkLRUItemUpdate () |
void | checkLRUMaxSize () |
void | clearSize () |
Private Attributes | |
list_t | mLruList |
map_t | mLruMap |
size_t | mMaxSize |
LRU map.
Similar to unordered_map (it actually uses it) with additionally functionality which removes the entries that have been "least recently used" when the size hits the specified capacity.
It only implements the minimal methods needed and the implementation is NOT thread safe.
The implementation is as simple as possible but it still uses O(1) complexity for most of the operations with a combination unordered map and linked list.
It is optionally possible to specify a function for ValueSize template argument (that can be called as 'size_t func(Value)') that will return a size (cost) for an item instead of the default size of 1 for each item. The size of an item must not change for an item (if needed, re-insert the item). A newly inserted item is guaranteed to be in the container, even if its size exceeds the maximum size.
Definition at line 66 of file lru_map.hxx.
typedef list_const_iterator_t o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::const_iterator |
Definition at line 167 of file lru_map.hxx.
typedef list_iterator_t o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::iterator |
Definition at line 166 of file lru_map.hxx.
typedef std::pair<Key, Value> o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::key_value_pair_t |
Definition at line 69 of file lru_map.hxx.
|
private |
Definition at line 74 of file lru_map.hxx.
|
private |
Definition at line 73 of file lru_map.hxx.
|
private |
Definition at line 72 of file lru_map.hxx.
|
private |
Definition at line 78 of file lru_map.hxx.
|
private |
Definition at line 77 of file lru_map.hxx.
|
private |
Definition at line 76 of file lru_map.hxx.
|
inline |
Definition at line 169 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mMaxSize.
|
inline |
|
inlineprivate |
Definition at line 84 of file lru_map.hxx.
References value.
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::insert().
|
inline |
Definition at line 276 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList.
|
inlineprivate |
Definition at line 111 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruMap, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mMaxSize, and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeOldestItem().
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::insert().
|
inlineprivate |
Definition at line 126 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mMaxSize, and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeOldestItem().
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::insert().
|
inlineprivate |
Definition at line 137 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruMap, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mMaxSize, and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeOldestItem().
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::setMaxSize().
|
inline |
|
inlineprivate |
Definition at line 151 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList, and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeSize().
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::clear(), and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::~lru_map().
|
inline |
Definition at line 278 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList.
|
inline |
Definition at line 243 of file lru_map.hxx.
References i, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList, and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruMap.
|
inline |
Definition at line 217 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::addSize(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemInsert(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemUpdate(), i, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruMap, and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeSize().
|
inline |
Definition at line 190 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::addSize(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemInsert(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemUpdate(), i, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruMap, and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeSize().
|
inline |
|
inlineprivate |
Definition at line 102 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList, o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruMap, and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeSize().
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemInsert(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemUpdate(), and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUMaxSize().
|
inlineprivate |
Definition at line 91 of file lru_map.hxx.
References value.
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::clearSize(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::insert(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::remove_if(), and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeOldestItem().
|
inline |
Definition at line 183 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUMaxSize(), and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mMaxSize.
|
inline |
Definition at line 280 of file lru_map.hxx.
References o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruList, and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::mLruMap.
|
private |
Definition at line 80 of file lru_map.hxx.
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::begin(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemInsert(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemUpdate(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::clear(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::clearSize(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::end(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::find(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::insert(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::remove_if(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeOldestItem(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::size(), and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::~lru_map().
|
private |
Definition at line 81 of file lru_map.hxx.
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemInsert(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUMaxSize(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::clear(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::find(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::insert(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::remove_if(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::removeOldestItem(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::size(), and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::~lru_map().
|
private |
Definition at line 82 of file lru_map.hxx.
Referenced by o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemInsert(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUItemUpdate(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::checkLRUMaxSize(), o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::lru_map(), and o3tl::lru_map< Key, Value, KeyHash, KeyEqual, ValueSize >::setMaxSize().