hash_fun.h

Go to the documentation of this file.
00001 // 'struct hash' from SGI -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00019 // USA. 00020 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 /* 00031 * Copyright (c) 1996-1998 00032 * Silicon Graphics Computer Systems, Inc. 00033 * 00034 * Permission to use, copy, modify, distribute and sell this software 00035 * and its documentation for any purpose is hereby granted without fee, 00036 * provided that the above copyright notice appear in all copies and 00037 * that both that copyright notice and this permission notice appear 00038 * in supporting documentation. Silicon Graphics makes no 00039 * representations about the suitability of this software for any 00040 * purpose. It is provided "as is" without express or implied warranty. 00041 * 00042 * 00043 * Copyright (c) 1994 00044 * Hewlett-Packard Company 00045 * 00046 * Permission to use, copy, modify, distribute and sell this software 00047 * and its documentation for any purpose is hereby granted without fee, 00048 * provided that the above copyright notice appear in all copies and 00049 * that both that copyright notice and this permission notice appear 00050 * in supporting documentation. Hewlett-Packard Company makes no 00051 * representations about the suitability of this software for any 00052 * purpose. It is provided "as is" without express or implied warranty. 00053 * 00054 */ 00055 00056 /** @file ext/hash_fun.h 00057 * This file is a GNU extension to the Standard C++ Library (possibly 00058 * containing extensions from the HP/SGI STL subset). You should only 00059 * include this header if you are using GCC 3 or later. 00060 */ 00061 00062 #ifndef _HASH_FUN_H 00063 #define _HASH_FUN_H 1 00064 00065 #include <cstddef> 00066 00067 namespace __gnu_cxx 00068 { 00069 using std::size_t; 00070 00071 template<class _Key> 00072 struct hash { }; 00073 00074 inline size_t 00075 __stl_hash_string(const char* __s) 00076 { 00077 unsigned long __h = 0; 00078 for ( ; *__s; ++__s) 00079 __h = 5 * __h + *__s; 00080 return size_t(__h); 00081 } 00082 00083 template<> 00084 struct hash<char*> 00085 { 00086 size_t 00087 operator()(const char* __s) const 00088 { return __stl_hash_string(__s); } 00089 }; 00090 00091 template<> 00092 struct hash<const char*> 00093 { 00094 size_t 00095 operator()(const char* __s) const 00096 { return __stl_hash_string(__s); } 00097 }; 00098 00099 template<> 00100 struct hash<char> 00101 { 00102 size_t 00103 operator()(char __x) const 00104 { return __x; } 00105 }; 00106 00107 template<> 00108 struct hash<unsigned char> 00109 { 00110 size_t 00111 operator()(unsigned char __x) const 00112 { return __x; } 00113 }; 00114 00115 template<> 00116 struct hash<signed char> 00117 { 00118 size_t 00119 operator()(unsigned char __x) const 00120 { return __x; } 00121 }; 00122 00123 template<> 00124 struct hash<short> 00125 { 00126 size_t 00127 operator()(short __x) const 00128 { return __x; } 00129 }; 00130 00131 template<> 00132 struct hash<unsigned short> 00133 { 00134 size_t 00135 operator()(unsigned short __x) const 00136 { return __x; } 00137 }; 00138 00139 template<> 00140 struct hash<int> 00141 { 00142 size_t 00143 operator()(int __x) const 00144 { return __x; } 00145 }; 00146 00147 template<> 00148 struct hash<unsigned int> 00149 { 00150 size_t 00151 operator()(unsigned int __x) const 00152 { return __x; } 00153 }; 00154 00155 template<> 00156 struct hash<long> 00157 { 00158 size_t 00159 operator()(long __x) const 00160 { return __x; } 00161 }; 00162 00163 template<> 00164 struct hash<unsigned long> 00165 { 00166 size_t 00167 operator()(unsigned long __x) const 00168 { return __x; } 00169 }; 00170 } // namespace __gnu_cxx 00171 00172 #endif

Generated on Sun Sep 12 15:49:57 2004 for libstdc++ source by doxygen 1.3.8