xref: /minix/minix/lib/libvtreefs/sdbm.c (revision e3b78ef1)
1 /* VTreeFS - sdbm.c - sdbm hash function */
2 
3 /*
4  * sdbm - ndbm work-alike hashed database library
5  * based on Per-Aake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
6  * author: oz@nexus.yorku.ca
7  * status: public domain. keep it that way.
8  *
9  * hashing routine
10  */
11 
12 #include "inc.h"
13 
14 /*
15  * polynomial conversion ignoring overflows
16  * [this seems to work remarkably well, in fact better
17  * than the ndbm hash function. Replace at your own risk]
18  * use: 65599	nice.
19  *      65587   even better.
20  */
21 long
22 sdbm_hash(const char *str, int len)
23 {
24 	unsigned long n = 0;
25 
26 	while (len--)
27 		n = *str++ + (n << 6) + (n << 16) - n;
28 
29 	return n;
30 }
31