00001 // 'struct hash' from SGI -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002 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/stl_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 _CPP_BITS_STL_HASH_FUN_H 00063 #define _CPP_BITS_STL_HASH_FUN_H 1 00064 00065 #include <cstddef> 00066 00067 namespace __gnu_cxx 00068 { 00069 using std::size_t; 00070 00071 template <class _Key> struct hash { }; 00072 00073 inline size_t __stl_hash_string(const char* __s) 00074 { 00075 unsigned long __h = 0; 00076 for ( ; *__s; ++__s) 00077 __h = 5*__h + *__s; 00078 00079 return size_t(__h); 00080 } 00081 00082 template<> struct hash<char*> 00083 { 00084 size_t operator()(const char* __s) const { return __stl_hash_string(__s); } 00085 }; 00086 00087 template<> struct hash<const char*> 00088 { 00089 size_t operator()(const char* __s) const { return __stl_hash_string(__s); } 00090 }; 00091 00092 template<> struct hash<char> { 00093 size_t operator()(char __x) const { return __x; } 00094 }; 00095 template<> struct hash<unsigned char> { 00096 size_t operator()(unsigned char __x) const { return __x; } 00097 }; 00098 template<> struct hash<signed char> { 00099 size_t operator()(unsigned char __x) const { return __x; } 00100 }; 00101 template<> struct hash<short> { 00102 size_t operator()(short __x) const { return __x; } 00103 }; 00104 template<> struct hash<unsigned short> { 00105 size_t operator()(unsigned short __x) const { return __x; } 00106 }; 00107 template<> struct hash<int> { 00108 size_t operator()(int __x) const { return __x; } 00109 }; 00110 template<> struct hash<unsigned int> { 00111 size_t operator()(unsigned int __x) const { return __x; } 00112 }; 00113 template<> struct hash<long> { 00114 size_t operator()(long __x) const { return __x; } 00115 }; 00116 template<> struct hash<unsigned long> { 00117 size_t operator()(unsigned long __x) const { return __x; } 00118 }; 00119 00120 } // namespace __gnu_cxx 00121 00122 #endif /* _CPP_BITS_STL_HASH_FUN_H */ 00123 00124 // Local Variables: 00125 // mode:C++ 00126 // End: