Implementation of copy-insert of LRU cache

This commit is contained in:
DennisOSRM 2012-06-12 13:25:38 +02:00
parent 8ddb3fc6ad
commit fa62f70cdf

View File

@ -53,6 +53,16 @@ public:
itemsInCache.pop_back();
}
}
void Insert(const KeyT key, ValueT value) {
itemsInCache.push_front(CacheEntry(key, value));
positionMap.insert(std::make_pair(key, itemsInCache.begin()));
if(itemsInCache.size() > capacity) {
positionMap.erase(itemsInCache.back().key);
itemsInCache.pop_back();
}
}
bool Fetch(const KeyT key, ValueT& result) {
if(Holds(key)) {
CacheEntry e = *(positionMap.find(key)->second);