3 #ifndef DUNE_COMMON_LRU_HH
4 #define DUNE_COMMON_LRU_HH
24 template <
typename _Key,
typename _Tp,
25 typename _Alloc = std::allocator<_Tp> >
26 struct _lru_default_traits
28 typedef _Key key_type;
29 typedef _Alloc allocator;
30 typedef std::list< std::pair<_Key, _Tp> > list_type;
31 typedef typename list_type::iterator
iterator;
32 typedef typename std::less<key_type> cmp;
33 typedef std::map< key_type,
iterator, cmp,
34 typename allocator::template rebind<std::pair<const key_type, iterator> >::other > map_type;
46 template <
typename _Key,
typename _Tp,
47 typename _Traits = _lru_default_traits<_Key, _Tp> >
50 typedef typename _Traits::list_type list_type;
51 typedef typename _Traits::map_type map_type;
52 typedef typename _Traits::allocator allocator;
53 typedef typename map_type::iterator map_iterator;
54 typedef typename map_type::const_iterator const_map_iterator;
59 typedef typename allocator::pointer
pointer;
73 return _data.front().second;
82 return _data.front().second;
91 return _data.back().second;
100 return _data.back().second;
130 const map_iterator it = _index.find(key);
131 if (it == _index.end())
return _data.end();
142 const map_iterator it = _index.find(key);
143 if (it == _index.end())
return _data.end();
160 std::pair<key_type, value_type> x(key, data);
162 iterator it = _data.insert(_data.begin(), x);
164 _index.insert(std::make_pair(key,it));
185 map_iterator it = _index.find(key);
186 if (it == _index.end())
188 "Failed to touch key " << key <<
", it is not in the lru container");
192 _data.splice(_data.begin(), _data, it->second);
193 return it->second->second;
212 assert(new_size <=
size());
214 while (new_size <
size())
235 #endif // DUNE_COMMON_LRU_HH