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

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 Brett's comments. Created 9 years, 5 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
Index: base/memory/mru_cache.h
diff --git a/base/memory/mru_cache.h b/base/memory/mru_cache.h
index 32a6fbbbdbe990223dff6cd85780b2f78949fe4d..18c12cd46474b2a79388e9fb89e333ce8cde6a65 100644
--- a/base/memory/mru_cache.h
+++ b/base/memory/mru_cache.h
@@ -23,15 +23,25 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/hash_tables.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 you 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_

Powered by Google App Engine
This is Rietveld 408576698