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

Last change on this file since 19594 was 15282, checked in by tbretz, 12 years ago
Updated to v20r7.
File size: 536 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 = (int)strlen(name);
31
32 for(i = 0; i < len; name++, i++)
33 {
34 hash = hash*a+(unsigned)(*name);
35 a = a*b;
36 }
37
38 return ((int)(hash % (unsigned)max));
39}
Note: See TracBrowser for help on using the repository browser.