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

Side by Side Diff: net/base/linked_hash_map.h

Issue 1666843002: Refactor StringPiece hash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sort includes. Created 4 years, 10 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
« no previous file with comments | « media/midi/midi_manager_alsa.h ('k') | net/dns/dns_hosts.h » ('j') | 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) 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.
11 // 11 //
12 // Iterators should be stable in the face of mutations, except for an 12 // Iterators should be stable in the face of mutations, except for an
13 // iterator pointing to an element that was just deleted. 13 // iterator pointing to an element that was just deleted.
14 14
15 #ifndef UTIL_GTL_LINKED_HASH_MAP_H_ 15 #ifndef UTIL_GTL_LINKED_HASH_MAP_H_
16 #define UTIL_GTL_LINKED_HASH_MAP_H_ 16 #define UTIL_GTL_LINKED_HASH_MAP_H_
17 17
18 #include <stddef.h> 18 #include <stddef.h>
19 19
20 #include <list> 20 #include <list>
21 #include <unordered_map>
21 #include <utility> 22 #include <utility>
22 23
23 #include "base/containers/hash_tables.h"
24 #include "base/logging.h" 24 #include "base/logging.h"
25 #include "base/macros.h" 25 #include "base/macros.h"
26 26
27 // This holds a list of pair<Key, Value> items. This list is what gets 27 // This holds a list of pair<Key, Value> items. This list is what gets
28 // traversed, and it's iterators from this list that we return from 28 // traversed, and it's iterators from this list that we return from
29 // begin/end/find. 29 // begin/end/find.
30 // 30 //
31 // We also keep a map<Key, list::iterator> for find. Since std::list is a 31 // We also keep a map<Key, list::iterator> for find. Since std::list is a
32 // doubly-linked list, the iterators should remain stable. 32 // doubly-linked list, the iterators should remain stable.
33 template<class Key, class Value> 33 template <class Key, class Value, class Hash = std::hash<Key>>
34 class linked_hash_map { 34 class linked_hash_map {
35 private: 35 private:
36 typedef std::list<std::pair<Key, Value> > ListType; 36 typedef std::list<std::pair<Key, Value> > ListType;
37 typedef base::hash_map<Key, typename ListType::iterator> MapType; 37 typedef std::unordered_map<Key, typename ListType::iterator, Hash> MapType;
38 38
39 public: 39 public:
40 typedef typename ListType::iterator iterator; 40 typedef typename ListType::iterator iterator;
41 typedef typename ListType::reverse_iterator reverse_iterator; 41 typedef typename ListType::reverse_iterator reverse_iterator;
42 typedef typename ListType::const_iterator const_iterator; 42 typedef typename ListType::const_iterator const_iterator;
43 typedef typename ListType::const_reverse_iterator const_reverse_iterator; 43 typedef typename ListType::const_reverse_iterator const_reverse_iterator;
44 typedef typename MapType::key_type key_type; 44 typedef typename MapType::key_type key_type;
45 typedef typename ListType::value_type value_type; 45 typedef typename ListType::value_type value_type;
46 typedef typename ListType::size_type size_type; 46 typedef typename ListType::size_type size_type;
47 47
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 235
236 // The list component, used for maintaining insertion order 236 // The list component, used for maintaining insertion order
237 ListType list_; 237 ListType list_;
238 238
239 // |map_| contains iterators to |list_|, therefore a default copy constructor 239 // |map_| contains iterators to |list_|, therefore a default copy constructor
240 // or copy assignment operator would result in an inconsistent state. 240 // or copy assignment operator would result in an inconsistent state.
241 DISALLOW_COPY_AND_ASSIGN(linked_hash_map); 241 DISALLOW_COPY_AND_ASSIGN(linked_hash_map);
242 }; 242 };
243 243
244 #endif // UTIL_GTL_LINKED_HASH_MAP_H_ 244 #endif // UTIL_GTL_LINKED_HASH_MAP_H_
OLDNEW
« no previous file with comments | « media/midi/midi_manager_alsa.h ('k') | net/dns/dns_hosts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698