blob: c2d3ddba158cf77cce5d21dbdb53935b33766cfc [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit3f4a7322008-07-27 06:49:38 +09004//
pinkerton@google.com3f807de2008-08-05 03:36:53 +09005
6//
initial.commit3f4a7322008-07-27 06:49:38 +09007// Deal with the differences between Microsoft and GNU implemenations
pinkerton@google.com3f807de2008-08-05 03:36:53 +09008// of hash_map. Allows all platforms to use |base::hash_map| and
9// |base::hash_set|.
10// eg:
11// base::hash_map<int> my_map;
12// base::hash_set<int> my_set;
initial.commit3f4a7322008-07-27 06:49:38 +090013//
14
15#ifndef BASE_HASH_TABLES_H__
16#define BASE_HASH_TABLES_H__
17
pinkerton@google.come3eb63f2008-08-06 23:36:32 +090018#include "build/build_config.h"
19
20#if defined(COMPILER_MSVC)
initial.commit3f4a7322008-07-27 06:49:38 +090021#include <hash_map>
22#include <hash_set>
23namespace base {
pinkerton@google.com3f807de2008-08-05 03:36:53 +090024using stdext::hash_map;
25using stdext::hash_set;
initial.commit3f4a7322008-07-27 06:49:38 +090026}
pinkerton@google.come3eb63f2008-08-06 23:36:32 +090027#elif defined(COMPILER_GCC)
initial.commit3f4a7322008-07-27 06:49:38 +090028#include <ext/hash_map>
29#include <ext/hash_set>
pinkerton@google.come3eb63f2008-08-06 23:36:32 +090030#include <tr1/functional>
initial.commit3f4a7322008-07-27 06:49:38 +090031namespace base {
pinkerton@google.com3f807de2008-08-05 03:36:53 +090032using __gnu_cxx::hash_map;
33using __gnu_cxx::hash_set;
34}
35
36// Implement string hash functions so that strings of various flavors can
37// be used as keys in STL maps and sets.
38namespace __gnu_cxx {
39
pinkerton@google.com3f807de2008-08-05 03:36:53 +090040template<>
41struct hash<wchar_t*> {
42 size_t operator()(const wchar_t* s) const {
pinkerton@google.come3eb63f2008-08-06 23:36:32 +090043 return std::tr1::hash<const wchar_t*>()(s);
pinkerton@google.com3f807de2008-08-05 03:36:53 +090044 }
45};
46
47template<>
48struct hash<const wchar_t*> {
49 size_t operator()(const wchar_t* s) const {
pinkerton@google.come3eb63f2008-08-06 23:36:32 +090050 return std::tr1::hash<const wchar_t*>()(s);
pinkerton@google.com3f807de2008-08-05 03:36:53 +090051 }
52};
53
54template<>
55struct hash<std::wstring> {
56 size_t operator()(const std::wstring& s) const {
pinkerton@google.come3eb63f2008-08-06 23:36:32 +090057 return std::tr1::hash<std::wstring>()(s);
pinkerton@google.com3f807de2008-08-05 03:36:53 +090058 }
59};
60
61template<>
62struct hash<const std::wstring> {
63 size_t operator()(const std::wstring& s) const {
pinkerton@google.come3eb63f2008-08-06 23:36:32 +090064 return std::tr1::hash<std::wstring>()(s);
pinkerton@google.com3f807de2008-08-05 03:36:53 +090065 }
66};
67
68template<>
69struct hash<std::string> {
70 size_t operator()(const std::string& s) const {
pinkerton@google.come3eb63f2008-08-06 23:36:32 +090071 return std::tr1::hash<std::string>()(s);
pinkerton@google.com3f807de2008-08-05 03:36:53 +090072 }
73};
74
75template<>
76struct hash<const std::string> {
77 size_t operator()(const std::string& s) const {
pinkerton@google.come3eb63f2008-08-06 23:36:32 +090078 return std::tr1::hash<std::string>()(s);
pinkerton@google.com3f807de2008-08-05 03:36:53 +090079 }
80};
81
initial.commit3f4a7322008-07-27 06:49:38 +090082}
83
84#endif
85
86#endif // BASE_HASH_TABLES_H__
license.botf003cfe2008-08-24 09:55:55 +090087