Added cache::erase and cache::size. Review: https://reviews.apache.org/r/19375
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/187dc509 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/187dc509 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/187dc509 Branch: refs/heads/master Commit: 187dc509d1d9e40914a62ba715c11b3e3932623f Parents: 9009d56 Author: Benjamin Mahler <[email protected]> Authored: Tue Mar 18 15:05:14 2014 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Thu Mar 20 15:13:35 2014 -0700 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/cache.hpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/187dc509/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp index 2bec13b..67b88bc 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp @@ -45,7 +45,7 @@ public: typedef boost::unordered_map< Key, std::pair<Value, typename list::iterator> > map; - explicit Cache(int _capacity) : capacity(_capacity) {} + explicit Cache(size_t _capacity) : capacity(_capacity) {} void put(const Key& key, const Value& value) { @@ -70,6 +70,22 @@ public: return None(); } + Option<Value> erase(const Key& key) + { + typename map::iterator i = values.find(key); + + if (i != values.end()) { + Value value = i->second.first; + keys.erase(i->second.second); + values.erase(i); + return value; + } + + return None(); + } + + size_t size() const { return keys.size(); } + private: // Not copyable, not assignable. Cache(const Cache&); @@ -114,7 +130,7 @@ private: } // Size of the cache. - int capacity; + const size_t capacity; // Cache of values and "pointers" into the least-recently used list. map values;
