hash.cc revision 58551
1/* 2Copyright (C) 1990 Free Software Foundation 3 written by Doug Lea (dl@rocky.oswego.edu) 4 5This file is part of the GNU C++ Library. This library is free 6software; you can redistribute it and/or modify it under the terms of 7the GNU Library General Public License as published by the Free 8Software Foundation; either version 2 of the License, or (at your 9option) any later version. This library is distributed in the hope 10that it will be useful, but WITHOUT ANY WARRANTY; without even the 11implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12PURPOSE. See the GNU Library General Public License for more details. 13You should have received a copy of the GNU Library General Public 14License along with this library; if not, write to the Free Software 15Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16*/ 17 18#include <hash.h> 19 20/* 21 some useful hash functions 22*/ 23 24unsigned int hashpjw (const char* x) // From Dragon book, p436 25{ 26 unsigned int h = 0; 27 unsigned int g; 28 29 while (*x != 0) 30 { 31 h = (h << 4) + (unsigned char) *x++; 32 if ((g = h & 0xf0000000) != 0) 33 h = (h ^ (g >> 24)) ^ g; 34 } 35 return h; 36} 37