# hash_fun.h

Go to the documentation of this file.

    00001 // 'struct hash' from SGI -*- C++ -*-
    00002
    00003 // Copyright (C) 2001, 2002, 2003 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 2, 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 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 /*
    00031  * Copyright (c) 1996-1998
    00032  * Silicon Graphics Computer Systems, Inc.
    00033  *
    00034  * Permission to use, copy, modify, distribute and sell this software
    00035  * and its documentation for any purpose is hereby granted without fee,
    00036  * provided that the above copyright notice appear in all copies and
    00037  * that both that copyright notice and this permission notice appear
    00038  * in supporting documentation.  Silicon Graphics makes no
    00039  * representations about the suitability of this software for any
    00040  * purpose.  It is provided "as is" without express or implied warranty.
    00041  *
    00042  *
    00043  * Copyright (c) 1994
    00044  * Hewlett-Packard Company
    00045  *
    00046  * Permission to use, copy, modify, distribute and sell this software
    00047  * and its documentation for any purpose is hereby granted without fee,
    00048  * provided that the above copyright notice appear in all copies and
    00049  * that both that copyright notice and this permission notice appear
    00050  * in supporting documentation.  Hewlett-Packard Company makes no
    00051  * representations about the suitability of this software for any
    00052  * purpose.  It is provided "as is" without express or implied warranty.
    00053  *
    00054  */
    00055
    00056 /** @file ext/hash_fun.h
    00057  *  This file is a GNU extension to the Standard C++ Library (possibly
    00058  *  containing extensions from the HP/SGI STL subset).  You should only
    00059  *  include this header if you are using GCC 3 or later.
    00060  */
    00061
    00062 #ifndef _HASH_FUN_H
    00063 #define _HASH_FUN_H 1
    00064
    00065 #include <cstddef>
    00066
    00067 namespace __gnu_cxx
    00068 {
    00069   using std::size_t;
    00070
    00071   template <class _Key> struct hash { };
    00072
    00073   inline size_t
    00074   __stl_hash_string(const char* __s)
    00075   {
    00076     unsigned long __h = 0;
    00077     for ( ; *__s; ++__s)
    00078       __h = 5*__h + *__s;
    00079     return size_t(__h);
    00080   }
    00081
    00082   template<> struct hash<char*>
    00083   {
    00084     size_t operator()(const char* __s) const
    00085     { return __stl_hash_string(__s); }
    00086   };
    00087
    00088   template<> struct hash<const char*>
    00089   {
    00090     size_t operator()(const char* __s) const
    00091     { return __stl_hash_string(__s); }
    00092   };
    00093
    00094   template<> struct hash<char>
    00095   { size_t operator()(char __x) const { return __x; } };
    00096
    00097   template<> struct hash<unsigned char>
    00098   { size_t operator()(unsigned char __x) const { return __x; } };
    00099
    00100   template<> struct hash<signed char>
    00101   { size_t operator()(unsigned char __x) const { return __x; } };
    00102
    00103   template<> struct hash<short>
    00104   { size_t operator()(short __x) const { return __x; } };
    00105
    00106   template<> struct hash<unsigned short>
    00107   { size_t operator()(unsigned short __x) const { return __x; } };
    00108
    00109   template<> struct hash<int>
    00110   { size_t operator()(int __x) const { return __x; } };
    00111
    00112   template<> struct hash<unsigned int>
    00113   { size_t operator()(unsigned int __x) const { return __x; } };
    00114
    00115   template<> struct hash<long>
    00116   { size_t operator()(long __x) const { return __x; } };
    00117
    00118   template<> struct hash<unsigned long>
    00119   { size_t operator()(unsigned long __x) const { return __x; } };
    00120 } // namespace __gnu_cxx
    00121
    00122 #endif