]>
Commit | Line | Data |
---|---|---|
42526146 PE |
1 | // 'struct hash' from SGI -*- C++ -*- |
2 | ||
a5544970 | 3 | // Copyright (C) 2001-2019 Free Software Foundation, Inc. |
42526146 PE |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
42526146 PE |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
42526146 | 19 | |
748086b7 JJ |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
42526146 | 24 | |
725dc051 BK |
25 | /* |
26 | * Copyright (c) 1996-1998 | |
27 | * Silicon Graphics Computer Systems, Inc. | |
28 | * | |
29 | * Permission to use, copy, modify, distribute and sell this software | |
30 | * and its documentation for any purpose is hereby granted without fee, | |
31 | * provided that the above copyright notice appear in all copies and | |
32 | * that both that copyright notice and this permission notice appear | |
33 | * in supporting documentation. Silicon Graphics makes no | |
34 | * representations about the suitability of this software for any | |
35 | * purpose. It is provided "as is" without express or implied warranty. | |
36 | * | |
37 | * | |
38 | * Copyright (c) 1994 | |
39 | * Hewlett-Packard Company | |
40 | * | |
41 | * Permission to use, copy, modify, distribute and sell this software | |
42 | * and its documentation for any purpose is hereby granted without fee, | |
43 | * provided that the above copyright notice appear in all copies and | |
44 | * that both that copyright notice and this permission notice appear | |
45 | * in supporting documentation. Hewlett-Packard Company makes no | |
46 | * representations about the suitability of this software for any | |
47 | * purpose. It is provided "as is" without express or implied warranty. | |
48 | * | |
49 | */ | |
50 | ||
e63637ea | 51 | /** @file backward/hash_fun.h |
ffe94f83 | 52 | * This file is a GNU extension to the Standard C++ Library (possibly |
0aa06b18 | 53 | * containing extensions from the HP/SGI STL subset). |
725dc051 BK |
54 | */ |
55 | ||
5ecfce5c PC |
56 | #ifndef _BACKWARD_HASH_FUN_H |
57 | #define _BACKWARD_HASH_FUN_H 1 | |
725dc051 | 58 | |
8fc81078 | 59 | #include <bits/c++config.h> |
725dc051 | 60 | |
12ffa228 BK |
61 | namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) |
62 | { | |
63 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
3cbc7af0 | 64 | |
b2acb86f BK |
65 | using std::size_t; |
66 | ||
4a787fa8 PC |
67 | template<class _Key> |
68 | struct hash { }; | |
b2acb86f | 69 | |
fa30fe72 | 70 | inline size_t |
b2acb86f BK |
71 | __stl_hash_string(const char* __s) |
72 | { | |
fa30fe72 | 73 | unsigned long __h = 0; |
b2acb86f | 74 | for ( ; *__s; ++__s) |
4a787fa8 | 75 | __h = 5 * __h + *__s; |
b2acb86f BK |
76 | return size_t(__h); |
77 | } | |
78 | ||
4a787fa8 PC |
79 | template<> |
80 | struct hash<char*> | |
81 | { | |
82 | size_t | |
83 | operator()(const char* __s) const | |
84 | { return __stl_hash_string(__s); } | |
85 | }; | |
86 | ||
87 | template<> | |
88 | struct hash<const char*> | |
89 | { | |
90 | size_t | |
91 | operator()(const char* __s) const | |
92 | { return __stl_hash_string(__s); } | |
93 | }; | |
94 | ||
95 | template<> | |
96 | struct hash<char> | |
97 | { | |
98 | size_t | |
99 | operator()(char __x) const | |
100 | { return __x; } | |
101 | }; | |
102 | ||
103 | template<> | |
104 | struct hash<unsigned char> | |
105 | { | |
106 | size_t | |
107 | operator()(unsigned char __x) const | |
108 | { return __x; } | |
109 | }; | |
110 | ||
111 | template<> | |
112 | struct hash<signed char> | |
113 | { | |
114 | size_t | |
115 | operator()(unsigned char __x) const | |
116 | { return __x; } | |
117 | }; | |
118 | ||
119 | template<> | |
120 | struct hash<short> | |
121 | { | |
122 | size_t | |
123 | operator()(short __x) const | |
124 | { return __x; } | |
125 | }; | |
126 | ||
127 | template<> | |
128 | struct hash<unsigned short> | |
129 | { | |
130 | size_t | |
131 | operator()(unsigned short __x) const | |
132 | { return __x; } | |
133 | }; | |
134 | ||
135 | template<> | |
136 | struct hash<int> | |
137 | { | |
138 | size_t | |
139 | operator()(int __x) const | |
140 | { return __x; } | |
141 | }; | |
142 | ||
143 | template<> | |
144 | struct hash<unsigned int> | |
145 | { | |
146 | size_t | |
147 | operator()(unsigned int __x) const | |
148 | { return __x; } | |
149 | }; | |
150 | ||
151 | template<> | |
152 | struct hash<long> | |
153 | { | |
154 | size_t | |
155 | operator()(long __x) const | |
156 | { return __x; } | |
157 | }; | |
158 | ||
159 | template<> | |
160 | struct hash<unsigned long> | |
161 | { | |
162 | size_t | |
163 | operator()(unsigned long __x) const | |
164 | { return __x; } | |
165 | }; | |
3cbc7af0 | 166 | |
12ffa228 BK |
167 | _GLIBCXX_END_NAMESPACE_VERSION |
168 | } // namespace | |
725dc051 | 169 | |
fa30fe72 | 170 | #endif |