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

Side by Side Diff: base/containers/mru_cache.h

Issue 17106004: Add discardable memory emulation for non-android/mac platforms (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2011 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.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 typename PayloadList::iterator iter = index_iter->second; 117 typename PayloadList::iterator iter = index_iter->second;
118 118
119 // Move the touched item to the front of the recency ordering. 119 // Move the touched item to the front of the recency ordering.
120 ordering_.splice(ordering_.begin(), ordering_, iter); 120 ordering_.splice(ordering_.begin(), ordering_, iter);
121 return ordering_.begin(); 121 return ordering_.begin();
122 } 122 }
123 123
124 // Retrieves the payload associated with a given key and returns it via 124 // Retrieves the payload associated with a given key and returns it via
125 // result without affecting the ordering (unlike Get). 125 // result without affecting the ordering (unlike Get).
126 // 126 //
127 // TODO(brettw) We may want a const version of this function in the future. 127 // TODO(brettw) We may want a const version of this function in the future.
Avi (use Gerrit) 2013/06/18 00:00:46 remove this comment since you did it
128 iterator Peek(const KeyType& key) { 128 iterator Peek(const KeyType& key) {
129 typename KeyIndex::const_iterator index_iter = index_.find(key); 129 typename KeyIndex::const_iterator index_iter = index_.find(key);
130 if (index_iter == index_.end()) 130 if (index_iter == index_.end())
131 return end(); 131 return end();
132 return index_iter->second; 132 return index_iter->second;
133 } 133 }
134 134
135 const_iterator Peek(const KeyType& key) const {
136 typename KeyIndex::const_iterator index_iter = index_.find(key);
137 if (index_iter == index_.end())
138 return end();
139 return index_iter->second;
140 }
141
135 // Erases the item referenced by the given iterator. An iterator to the item 142 // Erases the item referenced by the given iterator. An iterator to the item
136 // following it will be returned. The iterator must be valid. 143 // following it will be returned. The iterator must be valid.
137 iterator Erase(iterator pos) { 144 iterator Erase(iterator pos) {
138 deletor_(pos->second); 145 deletor_(pos->second);
139 index_.erase(pos->first); 146 index_.erase(pos->first);
140 return ordering_.erase(pos); 147 return ordering_.erase(pos);
141 } 148 }
142 149
143 // MRUCache entries are often processed in reverse order, so we add this 150 // MRUCache entries are often processed in reverse order, so we add this
144 // convenience function (not typically defined by STL containers). 151 // convenience function (not typically defined by STL containers).
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 virtual ~HashingMRUCache() { 303 virtual ~HashingMRUCache() {
297 } 304 }
298 305
299 private: 306 private:
300 DISALLOW_COPY_AND_ASSIGN(HashingMRUCache); 307 DISALLOW_COPY_AND_ASSIGN(HashingMRUCache);
301 }; 308 };
302 309
303 } // namespace base 310 } // namespace base
304 311
305 #endif // BASE_CONTAINERS_MRU_CACHE_H_ 312 #endif // BASE_CONTAINERS_MRU_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698