This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlapi: Add entry for hv_bucket_ratio
[perl5.git] / ext / SDBM_File / hash.c
CommitLineData
463ee0b2
LW
1/*
2 * sdbm - ndbm work-alike hashed database library
3 * based on Per-Aake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
4 * author: oz@nexus.yorku.ca
5 * status: public domain. keep it that way.
6 *
7 * hashing routine
8 */
9
85e6fe83 10#include "config.h"
17f28c40 11#include "EXTERN.h"
463ee0b2
LW
12#include "sdbm.h"
13/*
14 * polynomial conversion ignoring overflows
15 * [this seems to work remarkably well, in fact better
16 * then the ndbm hash function. Replace at your own risk]
17 * use: 65599 nice.
18 * 65587 even better.
19 */
20long
5aaab254 21sdbm_hash(const char *str, int len)
463ee0b2 22{
5aaab254 23 unsigned long n = 0;
463ee0b2
LW
24
25#ifdef DUFF
26
27#define HASHC n = *str++ + 65599 * n
28
29 if (len > 0) {
5aaab254 30 int loop = (len + 8 - 1) >> 3;
463ee0b2
LW
31
32 switch(len & (8 - 1)) {
33 case 0: do {
34 HASHC; case 7: HASHC;
35 case 6: HASHC; case 5: HASHC;
36 case 4: HASHC; case 3: HASHC;
37 case 2: HASHC; case 1: HASHC;
38 } while (--loop);
39 }
40
41 }
42#else
43 while (len--)
44 n = *str++ + 65599 * n;
45#endif
46 return n;
47}