Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1893)

Unified Diff: base/memory/mru_cache.h

Issue 7549003: Optimize phishing page term feature extraction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Brian's comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/i18n/case_conversion.cc ('k') | base/memory/mru_cache_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/mru_cache.h
diff --git a/base/memory/mru_cache.h b/base/memory/mru_cache.h
index 32a6fbbbdbe990223dff6cd85780b2f78949fe4d..434e5925e46bf92c3920cbb288eae55a92870ef8 100644
--- a/base/memory/mru_cache.h
+++ b/base/memory/mru_cache.h
@@ -22,16 +22,26 @@
#include <utility>
#include "base/basictypes.h"
+#include "base/hash_tables.h"
#include "base/logging.h"
namespace base {
// MRUCacheBase ----------------------------------------------------------------
+// This template is used to standardize map type containers that can be used
+// by MRUCacheBase. This level of indirection is necessary because of the way
+// that template template params and default template params interact.
+template <class KeyType, class ValueType>
+struct MRUCacheStandardMap {
+ typedef std::map<KeyType, ValueType> Type;
+};
+
// Base class for the MRU cache specializations defined below.
// The deletor will get called on all payloads that are being removed or
// replaced.
-template <class KeyType, class PayloadType, class DeletorType>
+template <class KeyType, class PayloadType, class DeletorType,
+ template <typename, typename> class MapType = MRUCacheStandardMap>
class MRUCacheBase {
public:
// The payload of the list. This maintains a copy of the key so we can
@@ -40,7 +50,8 @@ class MRUCacheBase {
private:
typedef std::list<value_type> PayloadList;
- typedef std::map<KeyType, typename PayloadList::iterator> KeyIndex;
+ typedef typename MapType<KeyType,
+ typename PayloadList::iterator>::Type KeyIndex;
public:
typedef typename PayloadList::size_type size_type;
@@ -258,6 +269,38 @@ class OwningMRUCache
DISALLOW_COPY_AND_ASSIGN(OwningMRUCache);
};
+// HashingMRUCache ------------------------------------------------------------
+
+template <class KeyType, class ValueType>
+struct MRUCacheHashMap {
+ typedef base::hash_map<KeyType, ValueType> Type;
+};
+
+// This class is similar to MRUCache, except that it uses base::hash_map as
+// the map type instead of std::map. Note that your KeyType must be hashable
+// to use this cache.
+template <class KeyType, class PayloadType>
+class HashingMRUCache : public MRUCacheBase<KeyType,
+ PayloadType,
+ MRUCacheNullDeletor<PayloadType>,
+ MRUCacheHashMap> {
+ private:
+ typedef MRUCacheBase<KeyType, PayloadType,
+ MRUCacheNullDeletor<PayloadType>,
+ MRUCacheHashMap> ParentType;
+
+ public:
+ // See MRUCacheBase, noting the possibility of using NO_AUTO_EVICT.
+ explicit HashingMRUCache(typename ParentType::size_type max_size)
+ : ParentType(max_size) {
+ }
+ virtual ~HashingMRUCache() {
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(HashingMRUCache);
+};
+
} // namespace base
#endif // BASE_MEMORY_MRU_CACHE_H_
« no previous file with comments | « base/i18n/case_conversion.cc ('k') | base/memory/mru_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698