summaryrefslogtreecommitdiff
path: root/unproto/hash.c
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1997-02-25 20:42:19 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:38:07 +0200
commit4c36e9a0c125ccfff37aa440dab2cf58c4152fff (patch)
treea5d9c84ba2661029ddb2223dacd50529a361c3d5 /unproto/hash.c
parentf8de35da65c5d93bb733073cf40da154bc1c0748 (diff)
parent9696d7b0e1f3a1b0f5fd4a0428eb75afe8ad4ed6 (diff)
downloaddev86-4c36e9a0c125ccfff37aa440dab2cf58c4152fff.tar.gz
Import Dev86src-0.0.11.tar.gzv0.0.11
Diffstat (limited to 'unproto/hash.c')
-rw-r--r--unproto/hash.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/unproto/hash.c b/unproto/hash.c
new file mode 100644
index 0000000..153f6b7
--- /dev/null
+++ b/unproto/hash.c
@@ -0,0 +1,54 @@
+/*++
+/* NAME
+/* hash 3
+/* SUMMARY
+/* compute hash value for string
+/* SYNOPSIS
+/* int hash(string, size)
+/* char *string;
+/* int size;
+/* DESCRIPTION
+/* This function computes for the given null-terminated string an
+/* integer hash value in the range 0..size-1.
+/* SEE ALSO
+/* .fi
+/* Alfred V. Aho, Ravi Sethi and Jeffrey D. Ullman: Compilers:
+/* principles, techniques and tools; Addison-Wesley, Amsterdam, 1986.
+/* AUTHOR(S)
+/* Wietse Venema
+/* Eindhoven University of Technology
+/* Department of Mathematics and Computer Science
+/* Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
+/*
+/* Originally written by: P. J. Weinberger at Bell Labs.
+/* LAST MODIFICATION
+/* 92/01/15 21:53:12
+/* VERSION/RELEASE
+/* %I
+/*--*/
+
+static char hash_sccsid[] = "@(#) hash.c 1.1 92/01/15 21:53:12";
+
+/* hash - hash a string; original author: P. J. Weinberger at Bell Labs. */
+
+int hash(s, size)
+register char *s;
+unsigned size;
+{
+ register unsigned long h = 0;
+ register unsigned long g;
+
+ /*
+ * For a performance comparison with the hash function presented in K&R,
+ * first edition, see the "Dragon" book by Aho, Sethi and Ullman.
+ */
+
+ while (*s) {
+ h = (h << 4) + *s++;
+ if (g = (h & 0xf0000000)) {
+ h ^= (g >> 24);
+ h ^= g;
+ }
+ }
+ return (h % size);
+}