1 // 'struct hash' from SGI -*- C++ -*- 2 3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation, Inc. 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 8 // Free Software Foundation; either version 3, or (at your option) 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 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. 19 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/>. 24 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 51 /** @file backward/hash_fun.h 52 * This file is a GNU extension to the Standard C++ Library (possibly 53 * containing extensions from the HP/SGI STL subset). 54 */ 55 56 #ifndef _HASH_FUN_H 57 #define _HASH_FUN_H 1 58 59 #include <cstddef> 60 61 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 62 63 using std::size_t; 64 65 template<class _Key> 66 struct hash { }; 67 68 inline size_t 69 __stl_hash_string(const char* __s) 70 { 71 unsigned long __h = 0; 72 for ( ; *__s; ++__s) 73 __h = 5 * __h + *__s; 74 return size_t(__h); 75 } 76 77 template<> 78 struct hash<char*> 79 { 80 size_t 81 operator()(const char* __s) const 82 { return __stl_hash_string(__s); } 83 }; 84 85 template<> 86 struct hash<const char*> 87 { 88 size_t 89 operator()(const char* __s) const 90 { return __stl_hash_string(__s); } 91 }; 92 93 template<> 94 struct hash<char> 95 { 96 size_t 97 operator()(char __x) const 98 { return __x; } 99 }; 100 101 template<> 102 struct hash<unsigned char> 103 { 104 size_t 105 operator()(unsigned char __x) const 106 { return __x; } 107 }; 108 109 template<> 110 struct hash<signed char> 111 { 112 size_t 113 operator()(unsigned char __x) const 114 { return __x; } 115 }; 116 117 template<> 118 struct hash<short> 119 { 120 size_t 121 operator()(short __x) const 122 { return __x; } 123 }; 124 125 template<> 126 struct hash<unsigned short> 127 { 128 size_t 129 operator()(unsigned short __x) const 130 { return __x; } 131 }; 132 133 template<> 134 struct hash<int> 135 { 136 size_t 137 operator()(int __x) const 138 { return __x; } 139 }; 140 141 template<> 142 struct hash<unsigned int> 143 { 144 size_t 145 operator()(unsigned int __x) const 146 { return __x; } 147 }; 148 149 template<> 150 struct hash<long> 151 { 152 size_t 153 operator()(long __x) const 154 { return __x; } 155 }; 156 157 template<> 158 struct hash<unsigned long> 159 { 160 size_t 161 operator()(unsigned long __x) const 162 { return __x; } 163 }; 164 165 _GLIBCXX_END_NAMESPACE 166 167 #endif 168