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

Side by Side Diff: content/common/mru_cache.h

Issue 6759068: Added another constructor to MRUCacheBase that specifies the deletor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 //
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 enum { NO_AUTO_EVICT = 0 }; 51 enum { NO_AUTO_EVICT = 0 };
52 52
53 // The max_size is the size at which the cache will prune its members to when 53 // The max_size is the size at which the cache will prune its members to when
54 // a new item is inserted. If the caller wants to manager this itself (for 54 // a new item is inserted. If the caller wants to manager this itself (for
55 // example, maybe it has special work to do when something is evicted), it 55 // example, maybe it has special work to do when something is evicted), it
56 // can pass NO_AUTO_EVICT to not restrict the cache size. 56 // can pass NO_AUTO_EVICT to not restrict the cache size.
57 explicit MRUCacheBase(size_type max_size) : max_size_(max_size) { 57 explicit MRUCacheBase(size_type max_size) : max_size_(max_size) {
58 } 58 }
59 59
60 MRUCacheBase(size_type max_size, const DeletorType& deletor)
61 : max_size_(max_size), deletor_(deletor) {
62 }
63
60 virtual ~MRUCacheBase() { 64 virtual ~MRUCacheBase() {
61 iterator i = begin(); 65 iterator i = begin();
62 while (i != end()) 66 while (i != end())
63 i = Erase(i); 67 i = Erase(i);
64 } 68 }
65 69
66 // Inserts a payload item with the given key. If an existing item has 70 // Inserts a payload item with the given key. If an existing item has
67 // the same key, it is removed prior to insertion. An iterator indicating the 71 // the same key, it is removed prior to insertion. An iterator indicating the
68 // inserted item will be returned (this will always be the front of the list). 72 // inserted item will be returned (this will always be the front of the list).
69 // 73 //
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 : ParentType(max_size) { 248 : ParentType(max_size) {
245 } 249 }
246 virtual ~OwningMRUCache() { 250 virtual ~OwningMRUCache() {
247 } 251 }
248 252
249 private: 253 private:
250 DISALLOW_COPY_AND_ASSIGN(OwningMRUCache); 254 DISALLOW_COPY_AND_ASSIGN(OwningMRUCache);
251 }; 255 };
252 256
253 #endif // CONTENT_COMMON_MRU_CACHE_H_ 257 #endif // CONTENT_COMMON_MRU_CACHE_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698