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