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