Index: base/containers/hash_tables.h |
diff --git a/base/containers/hash_tables.h b/base/containers/hash_tables.h |
index a1244f7b287e751cf9763047bae6ad0e5fbcffb4..d6d4377c77823478cd3eacd9535c54e4ac96ee0d 100644 |
--- a/base/containers/hash_tables.h |
+++ b/base/containers/hash_tables.h |
@@ -21,172 +21,83 @@ |
#ifndef BASE_CONTAINERS_HASH_TABLES_H_ |
#define BASE_CONTAINERS_HASH_TABLES_H_ |
+#include <unordered_map> |
+#include <unordered_set> |
#include <utility> |
#include "base/basictypes.h" |
-#include "base/strings/string16.h" |
-#include "build/build_config.h" |
- |
-#if defined(COMPILER_MSVC) |
-#include <unordered_map> |
-#include <unordered_set> |
+// Deprecated. Specialize std::hash directly instead. |
+// TODO(davidben): Or do we want to tell people to pass in a custom hasher? |
+// |
+// Things which specialize: |
+// - base::trace_event::AllocationContext |
+// - base::trace_event::BackTrace |
+// - base::FilePath (hashes the string) |
+// - base::StringPiece (hashes the string) |
+// - cc::RenderPassId (custom pair-like type, defines a custom hasher, defined |
+// in wrong file) |
+// - cc::SharedBitmapId (array, calls base::Hash, defined in wrong file, wrong |
+// module, even) |
+// - cc::SurfaceId (wrapper over a uint64_t, hashes that) |
+// - cc::SurfaceSequence (custom pair-like type) |
+// - cc::TileMapKey (custom pair-like type with custom hash) |
+// - content/renderer/pepper/v8_var_converter HashedHAndle (custom type with |
+// cached hash) |
+// - content::GpuMemoryBufferConfigurationKey (should be same as default) |
+// - data_reduction_proxy::ConnectionType (enum) |
+// - gfx::GenericSharedMemoryId (hashes int) |
+// - std::pair<gfx::GenericSharedMemoryId, Second> (unnecessary) |
+// - gn internal::UniquifyRef (caches the hash in a hash_val_) |
+// - gn Label (recursively calls std::hash) |
+// - gn LabelPtrPair (just hashes the label, also defines operator==) |
+// - gn OutputFile (hashes the string) |
+// - gn SourceDir (hashes the string) |
+// - gn SourceFile (hashes the string) |
+// - media::MultiBufferGlobalBlockId (std::pair, should be same as default one) |
+// - mojo::system::ChannelEndpointId (wrapper over integer) |
+// - mojo::system::UniqueIdentifier |
+// - net::DnsHostsKey (std::pair, but instead sums AddressFamily and StringPiece |
+// (not string?) hash) |
+// - net::AlternativeService (custom thing, XORs stuff) |
+// - net::QuicBlockedWriterInterface* (custom hash for a particular pointer, but |
+// only in GCC. I must have missed this last time. |
+// - password_manager::FacetURI |
+// - policy::PolicyNamespace (custom thing, hash string XOR 1<<enum) |
+// - signin AccountId (hashes just the email) |
+// - sync_file_system::drive_backend::ParentIDAndTitle (custom pair) |
#define BASE_HASH_NAMESPACE std |
-#elif defined(COMPILER_GCC) |
- |
-#define BASE_HASH_NAMESPACE base_hash |
- |
-// This is a hack to disable the gcc 4.4 warning about hash_map and hash_set |
-// being deprecated. We can get rid of this when we upgrade to VS2008 and we |
-// can use <tr1/unordered_map> and <tr1/unordered_set>. |
-#ifdef __DEPRECATED |
-#define CHROME_OLD__DEPRECATED __DEPRECATED |
-#undef __DEPRECATED |
-#endif |
- |
-#include <ext/hash_map> |
-#include <ext/hash_set> |
-#define BASE_HASH_IMPL_NAMESPACE __gnu_cxx |
- |
-#include <string> |
- |
-#ifdef CHROME_OLD__DEPRECATED |
-#define __DEPRECATED CHROME_OLD__DEPRECATED |
-#undef CHROME_OLD__DEPRECATED |
-#endif |
- |
-namespace BASE_HASH_NAMESPACE { |
- |
-// The pre-standard hash behaves like C++11's std::hash, except around pointers. |
-// const char* is specialized to hash the C string and hash functions for |
-// general T* are missing. Define a BASE_HASH_NAMESPACE::hash which aligns with |
-// the C++11 behavior. |
- |
-template<typename T> |
-struct hash { |
- std::size_t operator()(const T& value) const { |
- return BASE_HASH_IMPL_NAMESPACE::hash<T>()(value); |
- } |
-}; |
- |
-template<typename T> |
-struct hash<T*> { |
- std::size_t operator()(T* value) const { |
- return BASE_HASH_IMPL_NAMESPACE::hash<uintptr_t>()( |
- reinterpret_cast<uintptr_t>(value)); |
- } |
-}; |
- |
-// The GNU C++ library provides identity hash functions for many integral types, |
-// but not for |long long|. This hash function will truncate if |size_t| is |
-// narrower than |long long|. This is probably good enough for what we will |
-// use it for. |
- |
-#define DEFINE_TRIVIAL_HASH(integral_type) \ |
- template<> \ |
- struct hash<integral_type> { \ |
- std::size_t operator()(integral_type value) const { \ |
- return static_cast<std::size_t>(value); \ |
- } \ |
- } |
- |
-DEFINE_TRIVIAL_HASH(long long); |
-DEFINE_TRIVIAL_HASH(unsigned long long); |
- |
-#undef DEFINE_TRIVIAL_HASH |
- |
-// Implement string hash functions so that strings of various flavors can |
-// be used as keys in STL maps and sets. The hash algorithm comes from the |
-// GNU C++ library, in <tr1/functional>. It is duplicated here because GCC |
-// versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI |
-// is disabled, as it is in our build. |
- |
-#define DEFINE_STRING_HASH(string_type) \ |
- template<> \ |
- struct hash<string_type> { \ |
- std::size_t operator()(const string_type& s) const { \ |
- std::size_t result = 0; \ |
- for (string_type::const_iterator i = s.begin(); i != s.end(); ++i) \ |
- result = (result * 131) + *i; \ |
- return result; \ |
- } \ |
- } |
- |
-DEFINE_STRING_HASH(std::string); |
-DEFINE_STRING_HASH(base::string16); |
- |
-#undef DEFINE_STRING_HASH |
- |
-} // namespace BASE_HASH_NAMESPACE |
- |
-#else // COMPILER |
-#error define BASE_HASH_NAMESPACE for your compiler |
-#endif // COMPILER |
- |
namespace base { |
-// On MSVC, use the C++11 containers. |
-#if defined(COMPILER_MSVC) |
- |
+// Deprecated. Use std::unordered_map instead. |
template<class Key, class T, |
class Hash = std::hash<Key>, |
class Pred = std::equal_to<Key>, |
class Alloc = std::allocator<std::pair<const Key, T>>> |
using hash_map = std::unordered_map<Key, T, Hash, Pred, Alloc>; |
+// Deprecated. Use std::unordered_multimap instead. |
template<class Key, class T, |
class Hash = std::hash<Key>, |
class Pred = std::equal_to<Key>, |
class Alloc = std::allocator<std::pair<const Key, T>>> |
using hash_multimap = std::unordered_multimap<Key, T, Hash, Pred, Alloc>; |
+// Deprecated. Use std::unordered_multiset instead. |
template<class Key, |
class Hash = std::hash<Key>, |
class Pred = std::equal_to<Key>, |
class Alloc = std::allocator<Key>> |
using hash_multiset = std::unordered_multiset<Key, Hash, Pred, Alloc>; |
+// Deprecated. Use std::unordered_set instead. |
template<class Key, |
class Hash = std::hash<Key>, |
class Pred = std::equal_to<Key>, |
class Alloc = std::allocator<Key>> |
using hash_set = std::unordered_set<Key, Hash, Pred, Alloc>; |
-#else // !COMPILER_MSVC |
- |
-// Otherwise, use the pre-standard ones, but override the default hash to match |
-// C++11. |
-template<class Key, class T, |
- class Hash = BASE_HASH_NAMESPACE::hash<Key>, |
- class Pred = std::equal_to<Key>, |
- class Alloc = std::allocator<std::pair<const Key, T>>> |
-using hash_map = BASE_HASH_IMPL_NAMESPACE::hash_map<Key, T, Hash, Pred, Alloc>; |
- |
-template<class Key, class T, |
- class Hash = BASE_HASH_NAMESPACE::hash<Key>, |
- class Pred = std::equal_to<Key>, |
- class Alloc = std::allocator<std::pair<const Key, T>>> |
-using hash_multimap = |
- BASE_HASH_IMPL_NAMESPACE::hash_multimap<Key, T, Hash, Pred, Alloc>; |
- |
-template<class Key, |
- class Hash = BASE_HASH_NAMESPACE::hash<Key>, |
- class Pred = std::equal_to<Key>, |
- class Alloc = std::allocator<Key>> |
-using hash_multiset = |
- BASE_HASH_IMPL_NAMESPACE::hash_multiset<Key, Hash, Pred, Alloc>; |
- |
-template<class Key, |
- class Hash = BASE_HASH_NAMESPACE::hash<Key>, |
- class Pred = std::equal_to<Key>, |
- class Alloc = std::allocator<Key>> |
-using hash_set = BASE_HASH_IMPL_NAMESPACE::hash_set<Key, Hash, Pred, Alloc>; |
- |
-#undef BASE_HASH_IMPL_NAMESPACE |
- |
-#endif // COMPILER_MSVC |
- |
// Implement hashing for pairs of at-most 32 bit integer values. |
// When size_t is 32 bits, we turn the 64-bit hash code into 32 bits by using |
// multiply-add hashing. This algorithm, as described in |
@@ -264,6 +175,10 @@ namespace BASE_HASH_NAMESPACE { |
// Implement methods for hashing a pair of integers, so they can be used as |
// keys in STL containers. |
+// TODO(davidben): This is not present in C++11. How to transition this tidily? |
+// Should we keep a header around that specializes for std::pair (poor as it is |
+// not the same header std::pair is defined in) or ask people to pass in the |
+// third argument. I'm tempted to say the latter. |
template<typename Type1, typename Type2> |
struct hash<std::pair<Type1, Type2> > { |
std::size_t operator()(std::pair<Type1, Type2> value) const { |
@@ -273,7 +188,4 @@ struct hash<std::pair<Type1, Type2> > { |
} // namespace BASE_HASH_NAMESPACE |
-#undef DEFINE_PAIR_HASH_FUNCTION_START |
-#undef DEFINE_PAIR_HASH_FUNCTION_END |
- |
#endif // BASE_CONTAINERS_HASH_TABLES_H_ |