1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
* sdbm - ndbm work-alike hashed database library
19
* based on Per-Aake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
20
* author: oz@nexus.yorku.ca
21
* status: ex-public domain. keep it that way.
27
#include "sdbm_private.h"
30
* polynomial conversion ignoring overflows
31
* [this seems to work remarkably well, in fact better
32
* then the ndbm hash function. Replace at your own risk]
36
long sdbm_hash(const char *str, int len)
38
register unsigned long n = 0;
40
#define DUFF /* go ahead and use the loop-unrolled version */
43
#define HASHC n = *str++ + 65599 * n
46
register int loop = (len + 8 - 1) >> 3;
48
switch(len & (8 - 1)) {
51
case 6: HASHC; case 5: HASHC;
52
case 4: HASHC; case 3: HASHC;
53
case 2: HASHC; case 1: HASHC;
60
n = *str++ + 65599 * n;