hash_fun.h

Go to the documentation of this file.
00001 // 'struct hash' from SGI -*- C++ -*-
00002 
00003 // Copyright (C) 2001, 2002, 2003, 2004 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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 
00061 #ifndef _HASH_FUN_H
00062 #define _HASH_FUN_H 1
00063 
00064 #include <cstddef>
00065 
00066 namespace __gnu_cxx
00067 {
00068   using std::size_t;
00069 
00070   template<class _Key>
00071     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<>
00083     struct hash<char*>
00084     {
00085       size_t
00086       operator()(const char* __s) const
00087       { return __stl_hash_string(__s); }
00088     };
00089 
00090   template<>
00091     struct hash<const char*>
00092     {
00093       size_t
00094       operator()(const char* __s) const
00095       { return __stl_hash_string(__s); }
00096     };
00097 
00098   template<>
00099     struct hash<char>
00100     { 
00101       size_t
00102       operator()(char __x) const
00103       { return __x; }
00104     };
00105 
00106   template<>
00107     struct hash<unsigned char>
00108     { 
00109       size_t
00110       operator()(unsigned char __x) const
00111       { return __x; }
00112     };
00113 
00114   template<>
00115     struct hash<signed char>
00116     {
00117       size_t
00118       operator()(unsigned char __x) const
00119       { return __x; }
00120     };
00121 
00122   template<>
00123     struct hash<short>
00124     {
00125       size_t
00126       operator()(short __x) const
00127       { return __x; }
00128     };
00129 
00130   template<>
00131     struct hash<unsigned short>
00132     {
00133       size_t
00134       operator()(unsigned short __x) const
00135       { return __x; }
00136     };
00137 
00138   template<>
00139     struct hash<int>
00140     { 
00141       size_t 
00142       operator()(int __x) const 
00143       { return __x; }
00144     };
00145 
00146   template<>
00147     struct hash<unsigned int>
00148     { 
00149       size_t
00150       operator()(unsigned int __x) const
00151       { return __x; }
00152     };
00153 
00154   template<>
00155     struct hash<long>
00156     {
00157       size_t
00158       operator()(long __x) const
00159       { return __x; }
00160     };
00161 
00162   template<>
00163     struct hash<unsigned long>
00164     {
00165       size_t
00166       operator()(unsigned long __x) const
00167       { return __x; }
00168     };
00169 } // namespace __gnu_cxx
00170 
00171 #endif

Generated on Tue Feb 2 16:55:58 2010 for GNU C++ STL by  doxygen 1.4.7