| OLD | NEW |
| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 return index_.size(); | 174 return index_.size(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Allows iteration over the list. Forward iteration starts with the most | 177 // Allows iteration over the list. Forward iteration starts with the most |
| 178 // recent item and works backwards. | 178 // recent item and works backwards. |
| 179 // | 179 // |
| 180 // Note that since these iterators are actually iterators over a list, you | 180 // Note that since these iterators are actually iterators over a list, you |
| 181 // can keep them as you insert or delete things (as long as you don't delete | 181 // can keep them as you insert or delete things (as long as you don't delete |
| 182 // the one you are pointing to) and they will still be valid. | 182 // the one you are pointing to) and they will still be valid. |
| 183 iterator begin() { return ordering_.begin(); } | 183 iterator begin() { return ordering_.begin(); } |
| 184 const_iterator begin() const { ordering_.begin(); } | 184 const_iterator begin() const { return ordering_.begin(); } |
| 185 iterator end() { return ordering_.end(); } | 185 iterator end() { return ordering_.end(); } |
| 186 const_iterator end() const { return ordering_.end(); } | 186 const_iterator end() const { return ordering_.end(); } |
| 187 | 187 |
| 188 reverse_iterator rbegin() { return ordering_.rbegin(); } | 188 reverse_iterator rbegin() { return ordering_.rbegin(); } |
| 189 const_reverse_iterator rbegin() const { ordering_.rbegin(); } | 189 const_reverse_iterator rbegin() const { return ordering_.rbegin(); } |
| 190 reverse_iterator rend() { return ordering_.rend(); } | 190 reverse_iterator rend() { return ordering_.rend(); } |
| 191 const_reverse_iterator rend() const { return ordering_.rend(); } | 191 const_reverse_iterator rend() const { return ordering_.rend(); } |
| 192 | 192 |
| 193 bool empty() const { return ordering_.empty(); } | 193 bool empty() const { return ordering_.empty(); } |
| 194 | 194 |
| 195 private: | 195 private: |
| 196 PayloadList ordering_; | 196 PayloadList ordering_; |
| 197 KeyIndex index_; | 197 KeyIndex index_; |
| 198 | 198 |
| 199 size_type max_size_; | 199 size_type max_size_; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 virtual ~HashingMRUCache() { | 297 virtual ~HashingMRUCache() { |
| 298 } | 298 } |
| 299 | 299 |
| 300 private: | 300 private: |
| 301 DISALLOW_COPY_AND_ASSIGN(HashingMRUCache); | 301 DISALLOW_COPY_AND_ASSIGN(HashingMRUCache); |
| 302 }; | 302 }; |
| 303 | 303 |
| 304 } // namespace base | 304 } // namespace base |
| 305 | 305 |
| 306 #endif // BASE_MEMORY_MRU_CACHE_H_ | 306 #endif // BASE_MEMORY_MRU_CACHE_H_ |
| OLD | NEW |