source: trunk/FACT++/dim/src/hash.c@ 12410

Last change on this file since 12410 was 11071, checked in by tbretz, 13 years ago
Replaced v19r21 by a version extracted with 'unzip -a' to get proper unix text format.
File size: 504 bytes
Line 
1#define DIMLIB
2#include <dim.h>
3
4/*
5 * Hash function
6 */
7
8/*
9int HashFunction(name, max)
10char *name;
11int max;
12{
13 register int code = 0;
14
15 while(*name)
16 {
17 code += *name++;
18 }
19 return (code % max);
20}
21*/
22int HashFunction(char *name, int max)
23{
24 unsigned int b = 378551;
25 unsigned int a = 63689;
26 unsigned int hash = 0;
27 int i = 0;
28 int len;
29
30 len = strlen(name);
31
32 for(i = 0; i < len; name++, i++)
33 {
34 hash = hash*a+(*name);
35 a = a*b;
36 }
37
38 return (hash % max);
39}
Note: See TracBrowser for help on using the repository browser.