OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 is a simplistic insertion-ordered map. It behaves similarly to an STL | 5 // This is a simplistic insertion-ordered map. It behaves similarly to an STL |
6 // map, but only implements a small subset of the map's methods. Internally, we | 6 // map, but only implements a small subset of the map's methods. Internally, we |
7 // just keep a map and a list going in parallel. | 7 // just keep a map and a list going in parallel. |
8 // | 8 // |
9 // This class provides no thread safety guarantees, beyond what you would | 9 // This class provides no thread safety guarantees, beyond what you would |
10 // normally see with std::list. | 10 // normally see with std::list. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 | 73 |
74 // Returns an iterator beyond the first element. | 74 // Returns an iterator beyond the first element. |
75 reverse_iterator rend() { | 75 reverse_iterator rend() { |
76 return list_.rend(); | 76 return list_.rend(); |
77 } | 77 } |
78 const_reverse_iterator rend() const { | 78 const_reverse_iterator rend() const { |
79 return list_.rend(); | 79 return list_.rend(); |
80 } | 80 } |
81 | 81 |
| 82 // Front and back accessors common to many stl containers. |
| 83 |
| 84 // Returns the earliest-inserted element |
| 85 const value_type& front() const { |
| 86 return list_.front(); |
| 87 } |
| 88 |
| 89 // Returns the earliest-inserted element. |
| 90 value_type& front() { |
| 91 return list_.front(); |
| 92 } |
| 93 |
| 94 // Returns the most-recently-inserted element. |
| 95 const value_type& back() const { |
| 96 return list_.back(); |
| 97 } |
| 98 |
| 99 // Returns the most-recently-inserted element. |
| 100 value_type& back() { |
| 101 return list_.back(); |
| 102 } |
| 103 |
82 // Clears the map of all values. | 104 // Clears the map of all values. |
83 void clear() { | 105 void clear() { |
84 map_.clear(); | 106 map_.clear(); |
85 list_.clear(); | 107 list_.clear(); |
86 } | 108 } |
87 | 109 |
88 // Returns true iff the map is empty. | 110 // Returns true iff the map is empty. |
89 bool empty() const { | 111 bool empty() const { |
90 return list_.empty(); | 112 return list_.empty(); |
91 } | 113 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 223 |
202 private: | 224 private: |
203 // The map component, used for speedy lookups | 225 // The map component, used for speedy lookups |
204 MapType map_; | 226 MapType map_; |
205 | 227 |
206 // The list component, used for maintaining insertion order | 228 // The list component, used for maintaining insertion order |
207 ListType list_; | 229 ListType list_; |
208 }; | 230 }; |
209 | 231 |
210 #endif // UTIL_GTL_LINKED_HASH_MAP_H_ | 232 #endif // UTIL_GTL_LINKED_HASH_MAP_H_ |
OLD | NEW |