]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/gperf/lib/hash.cc
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / gperf / lib / hash.cc
1 /* 
2 Copyright (C) 1990, 2000, 2002 Free Software Foundation
3     written by Doug Lea <dl@rocky.oswego.edu>
4 */
5
6 #include <hash.h>
7
8 /*
9  Some useful hash function.
10  It's not a particularly good hash function (<< 5 would be better than << 4),
11  but people believe in it because it comes from Dragon book.
12 */
13
14 unsigned int
15 hashpjw (const unsigned char *x, unsigned int len) // From Dragon book, p436
16 {
17   unsigned int h = 0;
18   unsigned int g;
19
20   for (; len > 0; len--)
21     {
22       h = (h << 4) + *x++;
23       if ((g = h & 0xf0000000) != 0)
24         h = (h ^ (g >> 24)) ^ g;
25     }
26   return h;
27 }