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