source: trunk/FACT++/dim_v19r20/src/hash.c@ 10871

Last change on this file since 10871 was 10614, checked in by tbretz, 14 years ago
New release V19 r20
File size: 543 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.