OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains a template for a Most Recently Used cache that allows | 5 // This file contains a template for a Most Recently Used cache that allows |
6 // constant-time access to items using a key, but easy identification of the | 6 // constant-time access to items using a key, but easy identification of the |
7 // least-recently-used items for removal. Each key can only be associated with | 7 // least-recently-used items for removal. Each key can only be associated with |
8 // one payload item at a time. | 8 // one payload item at a time. |
9 // | 9 // |
10 // The key object will be stored twice, so it should support efficient copying. | 10 // The key object will be stored twice, so it should support efficient copying. |
11 // | 11 // |
12 // NOTE: While all operations are O(1), this code is written for | 12 // NOTE: While all operations are O(1), this code is written for |
13 // legibility rather than optimality. If future profiling identifies this as | 13 // legibility rather than optimality. If future profiling identifies this as |
14 // a bottleneck, there is room for smaller values of 1 in the O(1). :] | 14 // a bottleneck, there is room for smaller values of 1 in the O(1). :] |
15 | 15 |
16 #ifndef CHROME_COMMON_MRU_CACHE_H__ | 16 #ifndef CHROME_COMMON_MRU_CACHE_H__ |
17 #define CHROME_COMMON_MRU_CACHE_H__ | 17 #define CHROME_COMMON_MRU_CACHE_H__ |
18 | 18 |
19 #include <list> | 19 #include <list> |
20 #include <map> | 20 #include <map> |
21 #include <utility> | 21 #include <utility> |
22 | 22 |
23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
24 #include "chrome/common/logging_chrome.h" | 24 #include "base/logging.h" |
25 | 25 |
26 // MRUCacheBase ---------------------------------------------------------------- | 26 // MRUCacheBase ---------------------------------------------------------------- |
27 | 27 |
28 // Base class for the MRU cache specializations defined below. | 28 // Base class for the MRU cache specializations defined below. |
29 // The deletor will get called on all payloads that are being removed or | 29 // The deletor will get called on all payloads that are being removed or |
30 // replaced. | 30 // replaced. |
31 template <class KeyType, class PayloadType, class DeletorType> | 31 template <class KeyType, class PayloadType, class DeletorType> |
32 class MRUCacheBase { | 32 class MRUCacheBase { |
33 public: | 33 public: |
34 // The payload of the list. This maintains a copy of the key so we can | 34 // The payload of the list. This maintains a copy of the key so we can |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 : ParentType(max_size) { | 234 : ParentType(max_size) { |
235 } | 235 } |
236 virtual ~OwningMRUCache() { | 236 virtual ~OwningMRUCache() { |
237 } | 237 } |
238 | 238 |
239 private: | 239 private: |
240 DISALLOW_COPY_AND_ASSIGN(OwningMRUCache); | 240 DISALLOW_COPY_AND_ASSIGN(OwningMRUCache); |
241 }; | 241 }; |
242 | 242 |
243 #endif // CHROME_COMMON_MRU_CACHE_H__ | 243 #endif // CHROME_COMMON_MRU_CACHE_H__ |
OLD | NEW |