Whole document tree
    

Whole document tree

stl_hash_fun.h Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

stl_hash_fun.h

Go to the documentation of this file.
00001 // 'struct hash' from SGI -*- C++ -*-
00002 
00003 // Copyright (C) 2001 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 /* NOTE: This is an internal header file, included by other STL headers.
00057  *   You should not attempt to use it directly.
00058  */
00059 
00060 #ifndef _CPP_BITS_STL_HASH_FUN_H
00061 #define _CPP_BITS_STL_HASH_FUN_H 1
00062 
00063 #include <bits/std_cstddef.h>
00064 
00065 namespace std
00066 {
00067 
00068 template <class _Key> struct hash { };
00069 
00070 inline size_t __stl_hash_string(const char* __s)
00071 {
00072   unsigned long __h = 0; 
00073   for ( ; *__s; ++__s)
00074     __h = 5*__h + *__s;
00075   
00076   return size_t(__h);
00077 }
00078 
00079 template<> struct hash<char*>
00080 {
00081   size_t operator()(const char* __s) const { return __stl_hash_string(__s); }
00082 };
00083 
00084 template<> struct hash<const char*>
00085 {
00086   size_t operator()(const char* __s) const { return __stl_hash_string(__s); }
00087 };
00088 
00089 template<> struct hash<char> {
00090   size_t operator()(char __x) const { return __x; }
00091 };
00092 template<> struct hash<unsigned char> {
00093   size_t operator()(unsigned char __x) const { return __x; }
00094 };
00095 template<> struct hash<signed char> {
00096   size_t operator()(unsigned char __x) const { return __x; }
00097 };
00098 template<> struct hash<short> {
00099   size_t operator()(short __x) const { return __x; }
00100 };
00101 template<> struct hash<unsigned short> {
00102   size_t operator()(unsigned short __x) const { return __x; }
00103 };
00104 template<> struct hash<int> {
00105   size_t operator()(int __x) const { return __x; }
00106 };
00107 template<> struct hash<unsigned int> {
00108   size_t operator()(unsigned int __x) const { return __x; }
00109 };
00110 template<> struct hash<long> {
00111   size_t operator()(long __x) const { return __x; }
00112 };
00113 template<> struct hash<unsigned long> {
00114   size_t operator()(unsigned long __x) const { return __x; }
00115 };
00116 
00117 } // namespace std
00118 
00119 #endif /* _CPP_BITS_STL_HASH_FUN_H */
00120 
00121 // Local Variables:
00122 // mode:C++
00123 // End:

Generated on Mon Apr 8 03:11:40 2002 for libstdc++-v3 Source by doxygen1.2.15