1 #ifndef DUNE_COMMON_LRU_HH
2 #define DUNE_COMMON_LRU_HH
20 template <
typename _Key,
typename _Tp,
21 typename _Alloc = std::allocator<_Tp> >
22 struct _lru_default_traits
24 typedef _Key key_type;
25 typedef _Alloc allocator;
26 typedef std::list< std::pair<_Key, _Tp> > list_type;
27 typedef typename list_type::iterator iterator;
28 typedef typename std::less<key_type> cmp;
29 typedef std::map< key_type, iterator, cmp,
30 typename allocator::template rebind<std::pair<const key_type, iterator> >::other > map_type;
42 template <
typename _Key,
typename _Tp,
43 typename _Traits = _lru_default_traits<_Key, _Tp> >
46 typedef typename _Traits::list_type list_type;
47 typedef typename _Traits::map_type map_type;
48 typedef typename _Traits::allocator allocator;
49 typedef typename map_type::iterator map_iterator;
50 typedef typename map_type::const_iterator const_map_iterator;
55 typedef typename allocator::pointer
pointer;
69 return _data.front().second;
78 return _data.front().second;
87 return _data.back().second;
96 return _data.back().second;
126 const map_iterator it = _index.find(key);
127 if (it == _index.end())
return _data.end();
138 const map_iterator it = _index.find(key);
139 if (it == _index.end())
return _data.end();
155 std::pair<key_type, value_type> x(key, data);
157 iterator it = _data.insert(_data.begin(), x);
159 _index.insert(std::make_pair(key,it));
184 _data.splice(_data.begin(), _data, it);
201 assert(new_size <=
size());
203 while (new_size <
size())
224 #endif // DUNE_COMMON_LRU_HH