# 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 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 _HASH_FUN_H
    00057 #define _HASH_FUN_H 1
    00058
    00059 #include <cstddef>
    00060
    00061 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
    00062
    00063   using std::size_t;
    00064
    00065   template<class _Key>
    00066     struct hash { };
    00067
    00068   inline size_t
    00069   __stl_hash_string(const char* __s)
    00070   {
    00071     unsigned long __h = 0;
    00072     for ( ; *__s; ++__s)
    00073       __h = 5 * __h + *__s;
    00074     return size_t(__h);
    00075   }
    00076
    00077   template<>
    00078     struct hash<char*>
    00079     {
    00080       size_t
    00081       operator()(const char* __s) const
    00082       { return __stl_hash_string(__s); }
    00083     };
    00084
    00085   template<>
    00086     struct hash<const char*>
    00087     {
    00088       size_t
    00089       operator()(const char* __s) const
    00090       { return __stl_hash_string(__s); }
    00091     };
    00092
    00093   template<>
    00094     struct hash<char>
    00095     {
    00096       size_t
    00097       operator()(char __x) const
    00098       { return __x; }
    00099     };
    00100
    00101   template<>
    00102     struct hash<unsigned char>
    00103     {
    00104       size_t
    00105       operator()(unsigned char __x) const
    00106       { return __x; }
    00107     };
    00108
    00109   template<>
    00110     struct hash<signed char>
    00111     {
    00112       size_t
    00113       operator()(unsigned char __x) const
    00114       { return __x; }
    00115     };
    00116
    00117   template<>
    00118     struct hash<short>
    00119     {
    00120       size_t
    00121       operator()(short __x) const
    00122       { return __x; }
    00123     };
    00124
    00125   template<>
    00126     struct hash<unsigned short>
    00127     {
    00128       size_t
    00129       operator()(unsigned short __x) const
    00130       { return __x; }
    00131     };
    00132
    00133   template<>
    00134     struct hash<int>
    00135     {
    00136       size_t
    00137       operator()(int __x) const
    00138       { return __x; }
    00139     };
    00140
    00141   template<>
    00142     struct hash<unsigned int>
    00143     {
    00144       size_t
    00145       operator()(unsigned int __x) const
    00146       { return __x; }
    00147     };
    00148
    00149   template<>
    00150     struct hash<long>
    00151     {
    00152       size_t
    00153       operator()(long __x) const
    00154       { return __x; }
    00155     };
    00156
    00157   template<>
    00158     struct hash<unsigned long>
    00159     {
    00160       size_t
    00161       operator()(unsigned long __x) const
    00162       { return __x; }
    00163     };
    00164
    00165 _GLIBCXX_END_NAMESPACE
    00166
    00167 #endif