| Line |  | 
|---|
| 1 | #define DIMLIB | 
|---|
| 2 | #include <dim.h> | 
|---|
| 3 |  | 
|---|
| 4 | /* | 
|---|
| 5 | * Hash function | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | /* | 
|---|
| 9 | int HashFunction(name, max) | 
|---|
| 10 | char    *name; | 
|---|
| 11 | int     max; | 
|---|
| 12 | { | 
|---|
| 13 | register int code = 0; | 
|---|
| 14 |  | 
|---|
| 15 | while(*name) | 
|---|
| 16 | { | 
|---|
| 17 | code += *name++; | 
|---|
| 18 | } | 
|---|
| 19 | return (code % max); | 
|---|
| 20 | } | 
|---|
| 21 | */ | 
|---|
| 22 | int 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.