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