158551Skris/*
2228060SbaptCopyright (C) 1990, 2000, 2002 Free Software Foundation
3228060Sbapt    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
15228060Sbapthashpjw (const unsigned 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    {
22228060Sbapt      h = (h << 4) + *x++;
2367064Sobrien      if ((g = h & 0xf0000000) != 0)
2467064Sobrien        h = (h ^ (g >> 24)) ^ g;
2567064Sobrien    }
2658551Skris  return h;
2758551Skris}
28