hash.cc revision 67064
158551Skris/* 267064SobrienCopyright (C) 1990, 2000 Free Software Foundation 358551Skris written by Doug Lea (dl@rocky.oswego.edu) 458551Skris*/ 558551Skris 658551Skris#include <hash.h> 758551Skris 858551Skris/* 967064Sobrien Some useful hash function. 1067064Sobrien It's not a particularly good hash function (<< 5 would be better than << 4), 1167064Sobrien but people believe in it because it comes from Dragon book. 1258551Skris*/ 1358551Skris 1467064Sobrienunsigned int 1567064Sobrienhashpjw (const char *x, unsigned int len) // From Dragon book, p436 1658551Skris{ 1758551Skris unsigned int h = 0; 1858551Skris unsigned int g; 1958551Skris 2067064Sobrien for (; len > 0; len--) 2167064Sobrien { 2267064Sobrien h = (h << 4) + (unsigned char) *x++; 2367064Sobrien if ((g = h & 0xf0000000) != 0) 2467064Sobrien h = (h ^ (g >> 24)) ^ g; 2567064Sobrien } 2658551Skris return h; 2758551Skris} 28