1132720Skan// 'struct hash' from SGI -*- C++ -*- 2132720Skan 3169691Skan// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. 4132720Skan// 5132720Skan// This file is part of the GNU ISO C++ Library. This library is free 6132720Skan// software; you can redistribute it and/or modify it under the 7132720Skan// terms of the GNU General Public License as published by the 8132720Skan// Free Software Foundation; either version 2, or (at your option) 9132720Skan// any later version. 10132720Skan 11132720Skan// This library is distributed in the hope that it will be useful, 12132720Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 13132720Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14132720Skan// GNU General Public License for more details. 15132720Skan 16132720Skan// You should have received a copy of the GNU General Public License along 17132720Skan// with this library; see the file COPYING. If not, write to the Free 18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19132720Skan// USA. 20132720Skan 21132720Skan// As a special exception, you may use this file as part of a free software 22132720Skan// library without restriction. Specifically, if other files instantiate 23132720Skan// templates or use macros or inline functions from this file, or you compile 24132720Skan// this file and link it with other files to produce an executable, this 25132720Skan// file does not by itself cause the resulting executable to be covered by 26132720Skan// the GNU General Public License. This exception does not however 27132720Skan// invalidate any other reasons why the executable file might be covered by 28132720Skan// the GNU General Public License. 29132720Skan 30132720Skan/* 31132720Skan * Copyright (c) 1996-1998 32132720Skan * Silicon Graphics Computer Systems, Inc. 33132720Skan * 34132720Skan * Permission to use, copy, modify, distribute and sell this software 35132720Skan * and its documentation for any purpose is hereby granted without fee, 36132720Skan * provided that the above copyright notice appear in all copies and 37132720Skan * that both that copyright notice and this permission notice appear 38132720Skan * in supporting documentation. Silicon Graphics makes no 39132720Skan * representations about the suitability of this software for any 40132720Skan * purpose. It is provided "as is" without express or implied warranty. 41132720Skan * 42132720Skan * 43132720Skan * Copyright (c) 1994 44132720Skan * Hewlett-Packard Company 45132720Skan * 46132720Skan * Permission to use, copy, modify, distribute and sell this software 47132720Skan * and its documentation for any purpose is hereby granted without fee, 48132720Skan * provided that the above copyright notice appear in all copies and 49132720Skan * that both that copyright notice and this permission notice appear 50132720Skan * in supporting documentation. Hewlett-Packard Company makes no 51132720Skan * representations about the suitability of this software for any 52132720Skan * purpose. It is provided "as is" without express or implied warranty. 53132720Skan * 54132720Skan */ 55132720Skan 56132720Skan/** @file ext/hash_fun.h 57132720Skan * This file is a GNU extension to the Standard C++ Library (possibly 58169691Skan * containing extensions from the HP/SGI STL subset). 59132720Skan */ 60132720Skan 61132720Skan#ifndef _HASH_FUN_H 62132720Skan#define _HASH_FUN_H 1 63132720Skan 64132720Skan#include <cstddef> 65132720Skan 66169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 67169691Skan 68132720Skan using std::size_t; 69132720Skan 70169691Skan template<class _Key> 71169691Skan struct hash { }; 72132720Skan 73132720Skan inline size_t 74132720Skan __stl_hash_string(const char* __s) 75132720Skan { 76132720Skan unsigned long __h = 0; 77132720Skan for ( ; *__s; ++__s) 78169691Skan __h = 5 * __h + *__s; 79132720Skan return size_t(__h); 80132720Skan } 81132720Skan 82169691Skan template<> 83169691Skan struct hash<char*> 84169691Skan { 85169691Skan size_t 86169691Skan operator()(const char* __s) const 87169691Skan { return __stl_hash_string(__s); } 88169691Skan }; 89132720Skan 90169691Skan template<> 91169691Skan struct hash<const char*> 92169691Skan { 93169691Skan size_t 94169691Skan operator()(const char* __s) const 95169691Skan { return __stl_hash_string(__s); } 96169691Skan }; 97132720Skan 98169691Skan template<> 99169691Skan struct hash<char> 100169691Skan { 101169691Skan size_t 102169691Skan operator()(char __x) const 103169691Skan { return __x; } 104169691Skan }; 105132720Skan 106169691Skan template<> 107169691Skan struct hash<unsigned char> 108169691Skan { 109169691Skan size_t 110169691Skan operator()(unsigned char __x) const 111169691Skan { return __x; } 112169691Skan }; 113132720Skan 114169691Skan template<> 115169691Skan struct hash<signed char> 116169691Skan { 117169691Skan size_t 118169691Skan operator()(unsigned char __x) const 119169691Skan { return __x; } 120169691Skan }; 121132720Skan 122169691Skan template<> 123169691Skan struct hash<short> 124169691Skan { 125169691Skan size_t 126169691Skan operator()(short __x) const 127169691Skan { return __x; } 128169691Skan }; 129132720Skan 130169691Skan template<> 131169691Skan struct hash<unsigned short> 132169691Skan { 133169691Skan size_t 134169691Skan operator()(unsigned short __x) const 135169691Skan { return __x; } 136169691Skan }; 137132720Skan 138169691Skan template<> 139169691Skan struct hash<int> 140169691Skan { 141169691Skan size_t 142169691Skan operator()(int __x) const 143169691Skan { return __x; } 144169691Skan }; 145132720Skan 146169691Skan template<> 147169691Skan struct hash<unsigned int> 148169691Skan { 149169691Skan size_t 150169691Skan operator()(unsigned int __x) const 151169691Skan { return __x; } 152169691Skan }; 153132720Skan 154169691Skan template<> 155169691Skan struct hash<long> 156169691Skan { 157169691Skan size_t 158169691Skan operator()(long __x) const 159169691Skan { return __x; } 160169691Skan }; 161132720Skan 162169691Skan template<> 163169691Skan struct hash<unsigned long> 164169691Skan { 165169691Skan size_t 166169691Skan operator()(unsigned long __x) const 167169691Skan { return __x; } 168169691Skan }; 169132720Skan 170169691Skan_GLIBCXX_END_NAMESPACE 171169691Skan 172132720Skan#endif 173