From fa62f70cdf11fb2b47a4ef25ca35b66814cfc697 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Tue, 12 Jun 2012 13:25:38 +0200 Subject: [PATCH] Implementation of copy-insert of LRU cache --- DataStructures/LRUCache.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/DataStructures/LRUCache.h b/DataStructures/LRUCache.h index 3ac494351..a2c0b130d 100644 --- a/DataStructures/LRUCache.h +++ b/DataStructures/LRUCache.h @@ -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);