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