summaryrefslogtreecommitdiffstats
path: root/contrib/gperf/lib/hash.cc
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gperf/lib/hash.cc')
-rw-r--r--contrib/gperf/lib/hash.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/contrib/gperf/lib/hash.cc b/contrib/gperf/lib/hash.cc
new file mode 100644
index 0000000..b5bb4ad
--- /dev/null
+++ b/contrib/gperf/lib/hash.cc
@@ -0,0 +1,27 @@
+/*
+Copyright (C) 1990, 2000 Free Software Foundation
+ written by Doug Lea (dl@rocky.oswego.edu)
+*/
+
+#include <hash.h>
+
+/*
+ Some useful hash function.
+ It's not a particularly good hash function (<< 5 would be better than << 4),
+ but people believe in it because it comes from Dragon book.
+*/
+
+unsigned int
+hashpjw (const char *x, unsigned int len) // From Dragon book, p436
+{
+ unsigned int h = 0;
+ unsigned int g;
+
+ for (; len > 0; len--)
+ {
+ h = (h << 4) + (unsigned char) *x++;
+ if ((g = h & 0xf0000000) != 0)
+ h = (h ^ (g >> 24)) ^ g;
+ }
+ return h;
+}
OpenPOWER on IntegriCloud