CVC3
|
00001 /*****************************************************************************/ 00002 /*! 00003 *\file hash_fun.h 00004 *\brief hash functions 00005 * 00006 * Author: Alexander Fuchs 00007 * 00008 * Created: Fri Oct 20 11:04:00 2006 00009 * 00010 * <hr> 00011 * 00012 * License to use, copy, modify, sell and/or distribute this software 00013 * and its documentation for any purpose is hereby granted without 00014 * royalty, subject to the terms and conditions defined in the \ref 00015 * LICENSE file provided with this distribution. 00016 * 00017 * <hr> 00018 */ 00019 /*****************************************************************************/ 00020 00021 /* 00022 * Copyright (c) 1996-1998 00023 * Silicon Graphics Computer Systems, Inc. 00024 * 00025 * Permission to use, copy, modify, distribute and sell this software 00026 * and its documentation for any purpose is hereby granted without fee, 00027 * provided that the above copyright notice appear in all copies and 00028 * that both that copyright notice and this permission notice appear 00029 * in supporting documentation. Silicon Graphics makes no 00030 * representations about the suitability of this software for any 00031 * purpose. It is provided "as is" without express or implied warranty. 00032 * 00033 * 00034 * Copyright (c) 1994 00035 * Hewlett-Packard Company 00036 * 00037 * Permission to use, copy, modify, distribute and sell this software 00038 * and its documentation for any purpose is hereby granted without fee, 00039 * provided that the above copyright notice appear in all copies and 00040 * that both that copyright notice and this permission notice appear 00041 * in supporting documentation. Hewlett-Packard Company makes no 00042 * representations about the suitability of this software for any 00043 * purpose. It is provided "as is" without express or implied warranty. 00044 * 00045 */ 00046 00047 // this is basically (modulo renaming and namespace) the SGI implementation: 00048 // http://www.sgi.com/tech/stl/stl_hash_fun.h 00049 00050 #ifndef _cvc3__hash__hash_fun_h_ 00051 #define _cvc3__hash__hash_fun_h_ 00052 00053 // to get size_t 00054 #include <cstddef> 00055 00056 00057 namespace Hash { 00058 using std::size_t; 00059 00060 template <class _Key> struct hash { }; 00061 00062 inline size_t __stl_hash_string(const char* __s) 00063 { 00064 unsigned long __h = 0; 00065 for ( ; *__s; ++__s) 00066 __h = 5*__h + *__s; 00067 00068 return size_t(__h); 00069 } 00070 00071 template<> struct hash<char*> { 00072 size_t operator()(const char* __s) const { return __stl_hash_string(__s); } 00073 }; 00074 00075 template<> struct hash<const char*> 00076 { 00077 size_t operator()(const char* __s) const { return __stl_hash_string(__s); } 00078 }; 00079 00080 template<> struct hash<char> { 00081 size_t operator()(char __x) const { return __x; } 00082 }; 00083 00084 template<> struct hash<unsigned char> { 00085 size_t operator()(unsigned char __x) const { return __x; } 00086 }; 00087 00088 template<> struct hash<signed char> { 00089 size_t operator()(unsigned char __x) const { return __x; } 00090 }; 00091 00092 template<> struct hash<short> { 00093 size_t operator()(short __x) const { return __x; } 00094 }; 00095 00096 template<> struct hash<unsigned short> { 00097 size_t operator()(unsigned short __x) const { return __x; } 00098 }; 00099 00100 template<> struct hash<int> { 00101 size_t operator()(int __x) const { return __x; } 00102 }; 00103 00104 template<> struct hash<unsigned int> { 00105 size_t operator()(unsigned int __x) const { return __x; } 00106 }; 00107 00108 template<> struct hash<long> { 00109 size_t operator()(long __x) const { return __x; } 00110 }; 00111 00112 template<> struct hash<unsigned long> { 00113 size_t operator()(unsigned long __x) const { return __x; } 00114 }; 00115 00116 } 00117 00118 #endif