2 #ifndef __PCL_OUTOFCORE_LRU_CACHE__
3 #define __PCL_OUTOFCORE_LRU_CACHE__
26 template<
typename KeyT,
typename CacheItemT>
34 typedef std::map<KeyT, std::pair<CacheItemT, typename KeyIndex::iterator> >
Cache;
54 assert(it !=
cache_.end ());
60 return it->second.first;
68 assert(it !=
cache_.end ());
76 insert (
const KeyT& key,
const CacheItemT& value)
85 size_t item_size = value.sizeOf ();
96 size_t tail_timestamp = cache_it->second.first.timestamp;
97 size_t tail_size = cache_it->second.first.sizeOf ();
100 if (value.timestamp == tail_timestamp)
119 cache_.insert (std::make_pair (key, std::make_pair (value, it)));
134 return it->second.first;
140 return value.sizeOf ();
147 for (
int i=0; i < item_count; i++)
154 assert(it !=
cache_.end());
157 size_ -= it->second.first.sizeOf ();
178 #endif //__PCL_OUTOFCORE_LRU_CACHE__
std::list< KeyT > KeyIndex
virtual size_t sizeOf() const
void touch(const KeyT &key)
std::map< KeyT, std::pair< CacheItemT, typename KeyIndex::iterator > > Cache
size_t sizeOf(const CacheItemT &value)
bool hasKey(const KeyT &k)
void setCapacity(size_t capacity)
Cache::iterator CacheIterator
bool insert(const KeyT &key, const CacheItemT &value)
bool evict(int item_count=1)
KeyIndex::iterator KeyIndexIterator