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